Skip to content

Commit

Permalink
lsm_audit,selinux: pass IB device name by reference
Browse files Browse the repository at this point in the history
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 <omosnace@redhat.com>
Acked-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Ondrej Mosnacek authored and Paul Moore committed May 14, 2021
1 parent fd781f4 commit 869cbee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions include/linux/lsm_audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -6850,7 +6850,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,
Expand Down

0 comments on commit 869cbee

Please sign in to comment.