2013-08-08 06:47:26 +08:00
|
|
|
//===-- dfsan_interface.h -------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-08-08 06:47:26 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of DataFlowSanitizer.
|
|
|
|
//
|
|
|
|
// Public interface header.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef DFSAN_INTERFACE_H
|
|
|
|
#define DFSAN_INTERFACE_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sanitizer/common_interface_defs.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef uint16_t dfsan_label;
|
|
|
|
|
|
|
|
/// Stores information associated with a specific label identifier. A label
|
|
|
|
/// may be a base label created using dfsan_create_label, with associated
|
|
|
|
/// text description and user data, or an automatically created union label,
|
|
|
|
/// which represents the union of two label identifiers (which may themselves
|
|
|
|
/// be base or union labels).
|
|
|
|
struct dfsan_label_info {
|
|
|
|
// Fields for union labels, set to 0 for base labels.
|
|
|
|
dfsan_label l1;
|
|
|
|
dfsan_label l2;
|
|
|
|
|
|
|
|
// Fields for base labels.
|
|
|
|
const char *desc;
|
|
|
|
void *userdata;
|
|
|
|
};
|
|
|
|
|
2014-04-25 01:42:16 +08:00
|
|
|
/// Signature of the callback argument to dfsan_set_write_callback().
|
|
|
|
typedef void (*dfsan_write_callback_t)(int fd, const void *buf, size_t count);
|
|
|
|
|
2013-08-13 07:47:37 +08:00
|
|
|
/// Computes the union of \c l1 and \c l2, possibly creating a union label in
|
|
|
|
/// the process.
|
|
|
|
dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
|
|
|
|
|
2013-08-08 06:47:26 +08:00
|
|
|
/// Creates and returns a base label with the given description and user data.
|
|
|
|
dfsan_label dfsan_create_label(const char *desc, void *userdata);
|
|
|
|
|
|
|
|
/// Sets the label for each address in [addr,addr+size) to \c label.
|
|
|
|
void dfsan_set_label(dfsan_label label, void *addr, size_t size);
|
|
|
|
|
|
|
|
/// Sets the label for each address in [addr,addr+size) to the union of the
|
|
|
|
/// current label for that address and \c label.
|
|
|
|
void dfsan_add_label(dfsan_label label, void *addr, size_t size);
|
|
|
|
|
|
|
|
/// Retrieves the label associated with the given data.
|
|
|
|
///
|
|
|
|
/// The type of 'data' is arbitrary. The function accepts a value of any type,
|
|
|
|
/// which can be truncated or extended (implicitly or explicitly) as necessary.
|
|
|
|
/// The truncation/extension operations will preserve the label of the original
|
|
|
|
/// value.
|
|
|
|
dfsan_label dfsan_get_label(long data);
|
|
|
|
|
2013-08-14 06:15:40 +08:00
|
|
|
/// Retrieves the label associated with the data at the given address.
|
|
|
|
dfsan_label dfsan_read_label(const void *addr, size_t size);
|
|
|
|
|
2013-08-08 06:47:26 +08:00
|
|
|
/// Retrieves a pointer to the dfsan_label_info struct for the given label.
|
|
|
|
const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label);
|
|
|
|
|
|
|
|
/// Returns whether the given label label contains the label elem.
|
|
|
|
int dfsan_has_label(dfsan_label label, dfsan_label elem);
|
|
|
|
|
|
|
|
/// If the given label label contains a label with the description desc, returns
|
|
|
|
/// that label, else returns 0.
|
|
|
|
dfsan_label dfsan_has_label_with_desc(dfsan_label label, const char *desc);
|
|
|
|
|
2014-03-27 05:09:53 +08:00
|
|
|
/// Returns the number of labels allocated.
|
|
|
|
size_t dfsan_get_label_count(void);
|
|
|
|
|
2019-06-14 04:11:06 +08:00
|
|
|
/// Flushes the DFSan shadow, i.e. forgets about all labels currently associated
|
|
|
|
/// with the application memory. Will work only if there are no other
|
|
|
|
/// threads executing DFSan-instrumented code concurrently.
|
|
|
|
/// Use this call to start over the taint tracking within the same procces.
|
|
|
|
void dfsan_flush(void);
|
|
|
|
|
2014-04-25 01:42:16 +08:00
|
|
|
/// Sets a callback to be invoked on calls to write(). The callback is invoked
|
|
|
|
/// before the write is done. The write is not guaranteed to succeed when the
|
|
|
|
/// callback executes. Pass in NULL to remove any callback.
|
|
|
|
void dfsan_set_write_callback(dfsan_write_callback_t labeled_write_callback);
|
|
|
|
|
2014-11-20 18:01:08 +08:00
|
|
|
/// Writes the labels currently used by the program to the given file
|
|
|
|
/// descriptor. The lines of the output have the following format:
|
|
|
|
///
|
|
|
|
/// <label> <parent label 1> <parent label 2> <label description if any>
|
|
|
|
void dfsan_dump_labels(int fd);
|
|
|
|
|
2015-07-30 10:32:51 +08:00
|
|
|
/// Interceptor hooks.
|
2015-05-07 08:04:39 +08:00
|
|
|
/// Whenever a dfsan's custom function is called the corresponding
|
|
|
|
/// hook is called it non-zero. The hooks should be defined by the user.
|
|
|
|
/// The primary use case is taint-guided fuzzing, where the fuzzer
|
|
|
|
/// needs to see the parameters of the function and the labels.
|
|
|
|
/// FIXME: implement more hooks.
|
|
|
|
void dfsan_weak_hook_memcmp(void *caller_pc, const void *s1, const void *s2,
|
|
|
|
size_t n, dfsan_label s1_label,
|
|
|
|
dfsan_label s2_label, dfsan_label n_label);
|
2015-07-30 10:32:51 +08:00
|
|
|
void dfsan_weak_hook_strncmp(void *caller_pc, const char *s1, const char *s2,
|
|
|
|
size_t n, dfsan_label s1_label,
|
|
|
|
dfsan_label s2_label, dfsan_label n_label);
|
2013-08-08 06:47:26 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
template <typename T>
|
2013-08-14 00:52:07 +08:00
|
|
|
void dfsan_set_label(dfsan_label label, T &data) { // NOLINT
|
2013-08-08 06:47:26 +08:00
|
|
|
dfsan_set_label(label, (void *)&data, sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // DFSAN_INTERFACE_H
|