netmap: Ignore errors in CSB_WRITE()

The CSB_WRITE() and _READ() macros respectively write to and read from
userspace memory and so can in principle fault.  However, we do not
check for errors and will proceed blindly if they fail.  Add assertions
to verify that they do not.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by:	vmaffione
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43200

(cherry picked from commit 99efa2c88d93c6272a8f54b18d18d0fd9d60f137)
This commit is contained in:
Mark Johnston 2023-12-27 10:13:29 -05:00
parent 3e53fec002
commit aa545f18d3

View file

@ -2450,8 +2450,19 @@ void netmap_uninit_bridges(void);
#define CSB_READ(csb, field, r) (get_user(r, &csb->field))
#define CSB_WRITE(csb, field, v) (put_user(v, &csb->field))
#else /* ! linux */
#define CSB_READ(csb, field, r) (r = fuword32(&csb->field))
#define CSB_WRITE(csb, field, v) (suword32(&csb->field, v))
#define CSB_READ(csb, field, r) do { \
int32_t v __diagused; \
\
v = fuword32(&csb->field); \
KASSERT(v != -1, ("%s: fuword32 failed", __func__)); \
r = v; \
} while (0)
#define CSB_WRITE(csb, field, v) do { \
int error __diagused; \
\
error = suword32(&csb->field, v); \
KASSERT(error == 0, ("%s: suword32 failed", __func__)); \
} while (0)
#endif /* ! linux */
/* some macros that may not be defined */