Skip to content

Commit 869cbee

Browse files
WOnder93pcmoore
authored andcommitted
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. Signed-off-by: Ondrej Mosnacek <[email protected]> Acked-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent fd781f4 commit 869cbee

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/linux/lsm_audit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ struct lsm_ioctlop_audit {
4848
};
4949

5050
struct lsm_ibpkey_audit {
51-
u64 subnet_prefix;
52-
u16 pkey;
51+
u64 subnet_prefix;
52+
u16 pkey;
5353
};
5454

5555
struct lsm_ibendport_audit {
56-
char dev_name[IB_DEVICE_NAME_MAX];
57-
u8 port;
56+
const char *dev_name;
57+
u8 port;
5858
};
5959

6060
/* Auxiliary data to use in generating the audit record. */

security/selinux/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6850,7 +6850,7 @@ static int selinux_ib_endport_manage_subnet(void *ib_sec, const char *dev_name,
68506850
return err;
68516851

68526852
ad.type = LSM_AUDIT_DATA_IBENDPORT;
6853-
strncpy(ibendport.dev_name, dev_name, sizeof(ibendport.dev_name));
6853+
ibendport.dev_name = dev_name;
68546854
ibendport.port = port_num;
68556855
ad.u.ibendport = &ibendport;
68566856
return avc_has_perm(&selinux_state,

0 commit comments

Comments
 (0)