ipf: copy{in,out}ptr -> ipf_copy{in,out}_indirect

These functions take the source or destintation address indirectly from
a potentially missaligned buffer.  Rename them to refect this and to
free up the copy{in,out}ptr names.

Some of the code in question is dead code and doesn't or won't compile,
but I've changed it all for consistency.

NB: If the pointers are actually stored under aligned then this code is
broken with CHERI.

Reviewed by:	cy
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D54232
This commit is contained in:
Brooks Davis
2025-12-19 15:59:08 +00:00
parent df6861d755
commit a79e2278c5
7 changed files with 18 additions and 16 deletions
+2 -2
View File
@@ -619,7 +619,7 @@ ipf_checkv6sum(fin)
* See above for description, except that all addressing is in user space. * See above for description, except that all addressing is in user space.
*/ */
int int
copyoutptr(softc, src, dst, size) ipf_copyout_indirect(softc, src, dst, size)
void *src, *dst; void *src, *dst;
size_t size; size_t size;
{ {
@@ -635,7 +635,7 @@ copyoutptr(softc, src, dst, size)
* See above for description, except that all addressing is in user space. * See above for description, except that all addressing is in user space.
*/ */
int int
copyinptr(src, dst, size) ipf_copyin_indirect(src, dst, size)
void *src, *dst; void *src, *dst;
size_t size; size_t size;
{ {
+2 -2
View File
@@ -28,8 +28,8 @@ static ipf_error_entry_t *find_error(int);
static ipf_error_entry_t ipf_errors[] = { static ipf_error_entry_t ipf_errors[] = {
{ 1, "auth table locked/full" }, { 1, "auth table locked/full" },
{ 2, "" }, { 2, "" },
{ 3, "copyinptr received bad address" }, { 3, "ipf_copyin_indirect received bad address" },
{ 4, "copyoutptr received bad address" }, { 4, "ipf_copyout_indirect received bad address" },
{ 5, "" }, { 5, "" },
{ 6, "cannot load a rule with FR_T_BUILTIN flag set" }, { 6, "cannot load a rule with FR_T_BUILTIN flag set" },
{ 7, "internal rule without FR_T_BUILDINT flag set" }, { 7, "internal rule without FR_T_BUILDINT flag set" },
+4 -4
View File
@@ -4051,7 +4051,7 @@ ipf_sync(ipf_main_softc_t *softc, void *ifp)
* end up being unaligned) and on the kernel's local stack. * end up being unaligned) and on the kernel's local stack.
*/ */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/* Function: copyinptr */ /* Function: ipf_copyin_indirect */
/* Returns: int - 0 = success, else failure */ /* Returns: int - 0 = success, else failure */
/* Parameters: src(I) - pointer to the source address */ /* Parameters: src(I) - pointer to the source address */
/* dst(I) - destination address */ /* dst(I) - destination address */
@@ -4062,7 +4062,7 @@ ipf_sync(ipf_main_softc_t *softc, void *ifp)
/* NB: src - pointer to user space pointer, dst - kernel space pointer */ /* NB: src - pointer to user space pointer, dst - kernel space pointer */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
int int
copyinptr(ipf_main_softc_t *softc, void *src, void *dst, size_t size) ipf_copyin_indirect(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
{ {
caddr_t ca; caddr_t ca;
int error; int error;
@@ -4084,7 +4084,7 @@ copyinptr(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/* Function: copyoutptr */ /* Function: ipf_copyout_indirect */
/* Returns: int - 0 = success, else failure */ /* Returns: int - 0 = success, else failure */
/* Parameters: src(I) - pointer to the source address */ /* Parameters: src(I) - pointer to the source address */
/* dst(I) - destination address */ /* dst(I) - destination address */
@@ -4095,7 +4095,7 @@ copyinptr(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
/* NB: src - kernel space pointer, dst - pointer to user space pointer. */ /* NB: src - kernel space pointer, dst - pointer to user space pointer. */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
int int
copyoutptr(ipf_main_softc_t *softc, void *src, void *dst, size_t size) ipf_copyout_indirect(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
{ {
caddr_t ca; caddr_t ca;
int error; int error;
+3 -2
View File
@@ -1015,8 +1015,9 @@ ipf_auth_wait(ipf_main_softc_t *softc, ipf_auth_softc_t *softa, char *data)
for (t = auth.fra_buf; m && (len > 0); ) { for (t = auth.fra_buf; m && (len > 0); ) {
i = MIN(M_LEN(m), len); i = MIN(M_LEN(m), len);
error = copyoutptr(softc, MTOD(m, char *), error = ipf_copyout_indirect(softc,
&t, i); MTOD(m, char *),
&t, i);
len -= i; len -= i;
t += i; t += i;
if (error != 0) { if (error != 0) {
+3 -2
View File
@@ -1679,8 +1679,9 @@ extern char *getifname(struct ifnet *);
extern int ipfattach(ipf_main_softc_t *); extern int ipfattach(ipf_main_softc_t *);
extern int ipfdetach(ipf_main_softc_t *); extern int ipfdetach(ipf_main_softc_t *);
extern u_short ipf_cksum(u_short *, int); extern u_short ipf_cksum(u_short *, int);
extern int copyinptr(ipf_main_softc_t *, void *, void *, size_t); extern int ipf_copyin_indirect(ipf_main_softc_t *, void *, void *, size_t);
extern int copyoutptr(ipf_main_softc_t *, void *, void *, size_t); extern int ipf_copyout_indirect(ipf_main_softc_t *, void *, void *,
size_t);
extern int ipf_fastroute(mb_t *, mb_t **, fr_info_t *, frdest_t *); extern int ipf_fastroute(mb_t *, mb_t **, fr_info_t *, frdest_t *);
extern int ipf_inject(fr_info_t *, mb_t *); extern int ipf_inject(fr_info_t *, mb_t *);
extern int ipf_inobj(ipf_main_softc_t *, void *, ipfobj_t *, extern int ipf_inobj(ipf_main_softc_t *, void *, ipfobj_t *,
+2 -2
View File
@@ -700,8 +700,8 @@ ipf_proxy_ioctl(ipf_main_softc_t *softc, caddr_t data, ioctlcmd_t cmd,
IPFERROR(80003); IPFERROR(80003);
error = ENOMEM; error = ENOMEM;
} else { } else {
error = copyinptr(softc, ctl.apc_data, ptr, error = ipf_copyin_indirect(softc, ctl.apc_data,
ctl.apc_dsize); ptr, ctl.apc_dsize);
if (error == 0) if (error == 0)
ctl.apc_data = ptr; ctl.apc_data = ptr;
} }
+2 -2
View File
@@ -106,7 +106,7 @@ ipf_scan_add(caddr_t data)
return (ENOMEM); return (ENOMEM);
} }
err = copyinptr(data, isc, sizeof(*isc)); err = ipf_copyin_indirect(data, isc, sizeof(*isc));
if (err) { if (err) {
KFREE(isc); KFREE(isc);
return (err); return (err);
@@ -150,7 +150,7 @@ ipf_scan_remove(caddr_t data)
ipscan_t isc, *i; ipscan_t isc, *i;
int err; int err;
err = copyinptr(data, &isc, sizeof(isc)); err = ipf_copyin_indirect(data, &isc, sizeof(isc));
if (err) if (err)
return (err); return (err);