From 33d50e4e3029e25eaae48f331a8e7a9671f28326 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 12 May 2020 11:31:09 +0200 Subject: [PATCH] usb: Annotate access to USB buffers Annotate the USB transfer creation functions with the correct buffer access attribute. Note that we only annotate them as read_only as the functions may be used for sending and receiving. Hopefully this will catch buffer overflows in drivers in the future. --- libfprint/fpi-compat.h | 6 ++++++ libfprint/fpi-usb-transfer.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/libfprint/fpi-compat.h b/libfprint/fpi-compat.h index 59025e1..8b87913 100644 --- a/libfprint/fpi-compat.h +++ b/libfprint/fpi-compat.h @@ -37,3 +37,9 @@ typedef struct _FpDeviceClass FpDeviceClass; G_DEFINE_AUTOPTR_CLEANUP_FUNC (FpDeviceClass, g_type_class_unref); G_DEFINE_AUTOPTR_CLEANUP_FUNC (GDate, g_date_free); #endif + +#if __GNUC__ > 10 || (__GNUC__ == 10 && __GNUC_MINOR__ >= 1) +#define FP_GNUC_ACCESS(m, p, s) __attribute__((access (m, p, s))) +#else +#define FP_GNUC_ACCESS(m, p, s) +#endif diff --git a/libfprint/fpi-usb-transfer.h b/libfprint/fpi-usb-transfer.h index dc7fdb6..3770003 100644 --- a/libfprint/fpi-usb-transfer.h +++ b/libfprint/fpi-usb-transfer.h @@ -20,6 +20,7 @@ #pragma once #include +#include "fpi-compat.h" #include "fpi-device.h" G_BEGIN_DECLS @@ -115,6 +116,7 @@ void fpi_usb_transfer_fill_bulk (FpiUsbTransfer *transfer, guint8 endpoint, gsize length); +FP_GNUC_ACCESS (read_only, 3, 4) void fpi_usb_transfer_fill_bulk_full (FpiUsbTransfer *transfer, guint8 endpoint, guint8 *buffer, @@ -134,6 +136,7 @@ void fpi_usb_transfer_fill_interrupt (FpiUsbTransfer *transfer, guint8 endpoint, gsize length); +FP_GNUC_ACCESS (read_only, 3, 4) void fpi_usb_transfer_fill_interrupt_full (FpiUsbTransfer *transfer, guint8 endpoint, guint8 *buffer,