lsm_audit,selinux: pass IB device name by reference
Subsystems (2)
PATCH v2 1/1 lsm_audit,selinux: pass IB device name by reference
While trying to address a Coverity warning that the dev_name string might end up unterminated when strcpy'ing it in selinux_ib_endport_manage_subnet(), I realized that it is possible (and simpler) to just pass the dev_name pointer directly, rather than copying the string to a buffer.
The ibendport variable goes out of scope at the end of the function anyway, so the lifetime of the dev_name pointer will never be shorter than that of ibendport, thus we can safely just pass the dev_name pointer and be done with it.
--- include/linux/lsm_audit.h | 8 ++++---- security/selinux/hooks.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
v2: just pass the dev_name pointer and avoid the string copy
v1:
https://lore.kernel.org/selinux/[email protected]/T/
include/linux/lsm_audit.h +4 -4
@@ -48,13 +48,13 @@ struct lsm_ioctlop_audit { };struct lsm_ibpkey_audit { -u64 subnet_prefix; -u16 pkey; +u64 subnet_prefix; +u16 pkey; };struct lsm_ibendport_audit { -char dev_name[IB_DEVICE_NAME_MAX ]; -u8 port; +const char *dev_name; +u8 port; };/* Auxiliary data to use in generating the audit record. */
security/selinux/hooks.c +1 -1
@@ -6864,7 +6864,7 @@ static int selinux_ib_endport_manage_subnet(void *ib_sec, const char *dev_name,return err; ad.type =LSM_AUDIT_DATA_IBENDPORT ; -strncpy (ibendport.dev_name, dev_name,sizeof (ibendport.dev_name)); + ibendport.dev_name = dev_name; ibendport.port = port_num; ad.u.ibendport = &ibendport; return avc_has_perm(&selinux_state,
Signature · 1 line
2.31.1
Quoted 10 lines · Ondrej Mosnacek
While trying to address a Coverity warning that the
dev_namestring might end up unterminated when strcpy'ing it inselinux_ib_endport_manage_subnet(), I realized that it is possible (and simpler) to just pass thedev_namepointer directly, rather than copying the string to a buffer.The ibendport variable goes out of scope at the end of the function anyway, so the lifetime of the
dev_namepointer will never be shorter than that of ibendport, thus we can safely just pass thedev_namepointer and be done with it.
Agreed, this is better (other than the unrelated whitespace changes).
Quoted 1 line
Signed-off-by Ondrej Mosnacek <[email protected]>
Quoted 52 lines
--- include/linux/lsm_audit.h | 8 ++++---- security/selinux/hooks.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)v2: just pass the
dev_namepointer and avoid the string copyv1:
https://lore.kernel.org/selinux/[email protected]/T/include/linux/lsm_audit.h +4
-4@@ -48,13 +48,13 @@ struct lsm_ioctlop_audit { };struct lsm_ibpkey_audit { -u64 subnet_prefix; -u16 pkey; +u64 subnet_prefix; +u16 pkey; };struct lsm_ibendport_audit { -char dev_name[IB_DEVICE_NAME_MAX ]; -u8 port; +const char *dev_name; +u8 port; };/* Auxiliary data to use in generating the audit record. */ security/selinux/hooks.c +1
-1@@ -6864,7 +6864,7 @@ static int selinux_ib_endport_manage_subnet(void *ib_sec, const char *dev_name,return err; ad.type =LSM_AUDIT_DATA_IBENDPORT ; -strncpy (ibendport.dev_name, dev_name,sizeof (ibendport.dev_name)); + ibendport.dev_name = dev_name; ibendport.port = port_num; ad.u.ibendport = &ibendport; return avc_has_perm(&selinux_state,Signature · 6 lines
2.31.1 -- Linux-audit mailing list [email protected] https://listman.redhat.com/mailman/listinfo/linux-audit
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
--
Linux-audit mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-audit
Paul Moore
maintainerQuoted 12 lines · Ondrej Mosnacek
While trying to address a Coverity warning that the
dev_namestring might end up unterminated when strcpy'ing it inselinux_ib_endport_manage_subnet(), I realized that it is possible (and simpler) to just pass thedev_namepointer directly, rather than copying the string to a buffer.The ibendport variable goes out of scope at the end of the function anyway, so the lifetime of the
dev_namepointer will never be shorter than that of ibendport, thus we can safely just pass thedev_namepointer and be done with it.
Quoted 5 lines
Signed-off-by Ondrej Mosnacek <[email protected]>--- include/linux/lsm_audit.h | 8 ++++---- security/selinux/hooks.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
Much better, merged into selinux/next. Thanks.
Signature · 2 lines
paul moore www.paul-moore.com