From: Andrew Deason Date: Tue, 14 Jan 2020 16:51:42 +0000 (-0600) Subject: afs: Properly type afs_osi_suser cred arg X-Git-Tag: openafs-devel-1_9_0~141 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=4ce922d339777faf647f7129f5ae3f173a7870b1 afs: Properly type afs_osi_suser cred arg Currently, afs_osi_suser is declared with a void* argument, even though its only argument is always effectively a afs_ucred_t*. This allows us to call afs_osi_suser with any pointer type without the compiler complaining. Currently, some callers call afs_osi_suser with an incorrectly-typed afs_ucred_t** instead, like so: func(afs_ucred_t **credpp) { afs_ucred_t **acred = *acredpp; /* incorrect assignment */ if (afs_osi_suser(acred)) { /* ... */ } } The actual code in the tree hides this to some degree behind various function calls and layers of indirection (e.g. afs_suser()), but this is effectively what we do. This causes compiler warnings because we are doing incorrect pointer assignments, but the end result works because afs_osi_suser actually uses an afs_ucred_t*. The type confusion makes it very easy to accidentally give the wrong type to afs_osi_suser. This only really matters on SOLARIS, since that is the only platform that actually uses its argument to afs_osi_suser(). To fix all of this, just declare afs_osi_suser as taking an afs_ucred_t*, and fix all of the relevant functions to handle the right type. Change-Id: I1366aedf0f3d7689735a9424c5272233931e3bf2 Reviewed-on: https://gerrit.openafs.org/14085 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- diff --git a/src/afs/AIX/osi_misc.c b/src/afs/AIX/osi_misc.c index 77609a9..be4336a 100644 --- a/src/afs/AIX/osi_misc.c +++ b/src/afs/AIX/osi_misc.c @@ -167,7 +167,7 @@ aix_gnode_rele(vp) * Note that it must NOT set errno. */ -afs_suser(void *credp) +afs_suser(afs_ucred_t *credp) { int rc; char err; diff --git a/src/afs/DARWIN/osi_misc.c b/src/afs/DARWIN/osi_misc.c index 22dcfb0..b0e006f 100644 --- a/src/afs/DARWIN/osi_misc.c +++ b/src/afs/DARWIN/osi_misc.c @@ -170,7 +170,7 @@ osi_lookupname(char *aname, enum uio_seg seg, int followlink, * Note that it must NOT set errno. */ int -afs_suser(void *credp) +afs_suser(afs_ucred_t *credp) { int error; struct proc *p = current_proc(); diff --git a/src/afs/DARWIN/osi_prototypes.h b/src/afs/DARWIN/osi_prototypes.h index c93cf5b..9562112 100644 --- a/src/afs/DARWIN/osi_prototypes.h +++ b/src/afs/DARWIN/osi_prototypes.h @@ -20,7 +20,7 @@ extern int osi_lookupname(char *aname, enum uio_seg seg, int followlink, struct vnode **vpp); extern int osi_lookupname_user(user_addr_t aname, enum uio_seg seg, int followlink, struct vnode **vpp); -extern int afs_suser(void *credp); +extern int afs_suser(afs_ucred_t *credp); extern void get_vfs_context(void); extern void put_vfs_context(void); diff --git a/src/afs/HPUX/osi_misc.c b/src/afs/HPUX/osi_misc.c index c80bf6a..ab2eec7 100644 --- a/src/afs/HPUX/osi_misc.c +++ b/src/afs/HPUX/osi_misc.c @@ -27,7 +27,7 @@ * Here we have to save and restore errno since the HP-UX suser() sets errno. */ -afs_suser(void *credp) +afs_suser(afs_ucred_t *credp) { int save_errno; int code; diff --git a/src/afs/NBSD/osi_misc.c b/src/afs/NBSD/osi_misc.c index dd10f06..2f6f1c4 100644 --- a/src/afs/NBSD/osi_misc.c +++ b/src/afs/NBSD/osi_misc.c @@ -62,7 +62,7 @@ such damages. * traditional BSD suser, see OBSD/osi_misc.c. */ int -afs_osi_suser(void *credp) +afs_osi_suser(afs_ucred_t *credp) { int code; /* diff --git a/src/afs/OBSD/osi_misc.c b/src/afs/OBSD/osi_misc.c index 0d17ef1..5a7778a 100644 --- a/src/afs/OBSD/osi_misc.c +++ b/src/afs/OBSD/osi_misc.c @@ -65,7 +65,7 @@ such damages. */ int -afs_osi_suser(void *credp) +afs_osi_suser(afs_ucred_t *credp) { #ifdef AFS_OBSD35_ENV return (suser_ucred((struct ucred *)credp) ? 0 : 1); diff --git a/src/afs/UKERNEL/afs_usrops.c b/src/afs/UKERNEL/afs_usrops.c index 0e38fb8..e11e281 100644 --- a/src/afs/UKERNEL/afs_usrops.c +++ b/src/afs/UKERNEL/afs_usrops.c @@ -166,13 +166,13 @@ getf(int fd) * Every user is a super user */ int -afs_osi_suser(void *credp) +afs_osi_suser(afs_ucred_t *credp) { return 1; } int -afs_suser(void *credp) +afs_suser(afs_ucred_t *credp) { return 1; } diff --git a/src/afs/UKERNEL/osi_machdep.h b/src/afs/UKERNEL/osi_machdep.h index cd2a555..97fa93f 100644 --- a/src/afs/UKERNEL/osi_machdep.h +++ b/src/afs/UKERNEL/osi_machdep.h @@ -78,7 +78,7 @@ extern usr_mutex_t afs_global_lock; extern int afs_bufferpages; -extern int afs_suser(void *credp); +extern int afs_suser(afs_ucred_t *credp); #define setuerror(erval) get_user_struct()->u_error = (erval) #define getuerror(erval) get_user_struct()->u_error diff --git a/src/afs/afs_osi.c b/src/afs/afs_osi.c index c970ea3..1289d22 100644 --- a/src/afs/afs_osi.c +++ b/src/afs/afs_osi.c @@ -263,7 +263,7 @@ shutdown_osisleep(void) #if !defined(AFS_OBSD_ENV) && !defined(AFS_NBSD40_ENV) int -afs_osi_suser(void *cr) +afs_osi_suser(afs_ucred_t *cr) { #if defined(AFS_SUN510_ENV) return (priv_policy(cr, PRIV_SYS_SUSER_COMPAT, B_FALSE, EPERM, NULL) == 0); diff --git a/src/afs/afs_osi_pag.c b/src/afs/afs_osi_pag.c index 22167f0..c0667d9 100644 --- a/src/afs/afs_osi_pag.c +++ b/src/afs/afs_osi_pag.c @@ -139,7 +139,7 @@ static int afs_pag_sleepcnt = 0; static int afs_pag_timewarn = 0; static int -afs_pag_sleep(afs_ucred_t **acred) +afs_pag_sleep(afs_ucred_t *acred) { int rv = 0; @@ -160,7 +160,7 @@ afs_pag_sleep(afs_ucred_t **acred) } static int -afs_pag_wait(afs_ucred_t **acred) +afs_pag_wait(afs_ucred_t *acred) { int code = 0; @@ -197,11 +197,11 @@ afs_setpag(void) { #if defined(AFS_SUN5_ENV) - afs_ucred_t **acred = *credpp; + afs_ucred_t *acred = *credpp; #elif defined(AFS_OBSD_ENV) - afs_ucred_t **acred = &p->p_ucred; + afs_ucred_t *acred = p->p_ucred; #else - afs_ucred_t **acred = NULL; + afs_ucred_t *acred = NULL; #endif int code = 0; @@ -311,11 +311,11 @@ afs_setpag_val(int pagval) { #if defined(AFS_SUN5_ENV) - afs_ucred_t **acred = *credp; + afs_ucred_t *acred = *credp; #elif defined(AFS_OBSD_ENV) - afs_ucred_t **acred = &p->p_ucred; + afs_ucred_t *acred = p->p_ucred; #else - afs_ucred_t **acred = NULL; + afs_ucred_t *acred = NULL; #endif int code = 0; diff --git a/src/afs/afs_pioctl.c b/src/afs/afs_pioctl.c index c97d0f4..eee4d88 100644 --- a/src/afs/afs_pioctl.c +++ b/src/afs/afs_pioctl.c @@ -5159,7 +5159,7 @@ DECL_PIOCTL(PCallBackAddr) if (!afs_resourceinit_flag) /* afs deamons havn't started yet */ return EIO; /* Inappropriate ioctl for device */ - if (!afs_osi_suser(acred)) + if (!afs_osi_suser(*acred)) return EACCES; if (afs_pd_getInt(ain, &addr) != 0) @@ -5564,7 +5564,7 @@ DECL_PIOCTL(PNFSNukeCreds) return EACCES; } afs_PutUser(tu, SHARED_LOCK); - } else if (!afs_osi_suser(acred)) { + } else if (!afs_osi_suser(*acred)) { return EACCES; } diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index da79b61..3cf4394 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -552,7 +552,7 @@ extern void afs_osi_Invisible(void); extern void shutdown_osi(void); extern void shutdown_osinet(void); extern void shutdown_osisleep(void); -extern int afs_osi_suser(void *credp); +extern int afs_osi_suser(afs_ucred_t *credp); extern void afs_osi_TraverseProcTable(void); #if defined(KERNEL) && !defined(UKERNEL) extern const afs_ucred_t *afs_osi_proc2cred(afs_proc_t * pr);