ipc: don't audit capability check in ipc_permissions()
Subsystems (3)
PATCH 1/1 ipc: don't audit capability check in ipc_permissions()
The IPC sysctls implement the ctl_table_root::permissions hook and they override the file access mode based on the CAP_CHECKPOINT_RESTORE capability, which is being checked regardless of whether any access is actually denied or not, so if an LSM denies the capability, an audit record may be logged even when access is in fact granted.
It wouldn't be viable to restructure the sysctl permission logic to only check the capability when the access would be actually denied if it's not granted. Thus, do the same as in net_ctl_permissions() (net/sysctl_net.c) - switch from ns_capable() to ns_capable_noaudit(), so that the check never emits an audit record.
--- include/linux/capability.h | 6 ++++++ ipc/ipc_sysctl.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/capability.h +6 -0
@@ -203,6 +203,12 @@ static inline bool checkpoint_restore_ns_capable(struct user_namespace *ns)ns_capable (ns,CAP_SYS_ADMIN ); } +static inline bool checkpoint_restore_ns_capable_noaudit (struct user_namespace *ns) +{ +return ns_capable_noaudit (ns,CAP_CHECKPOINT_RESTORE ) || +ns_capable_noaudit (ns,CAP_SYS_ADMIN ); +} +/* audit system wants to get cap info from files as well */ int get_vfs_caps_from_disk(struct mnt_idmap *idmap, const struct dentry *dentry,
ipc/ipc_sysctl.c +1 -1
@@ -214,7 +214,7 @@ static int ipc_permissions(struct ctl_table_header *head, const struct ctl_tableif (((table->data == &ns->ids[IPC_SEM_IDS ].next_id) || (table->data == &ns->ids[IPC_MSG_IDS ].next_id) || (table->data == &ns->ids[IPC_SHM_IDS ].next_id)) && -checkpoint_restore_ns_capable (ns->user_ns)) +checkpoint_restore_ns_capable_noaudit (ns->user_ns)) mode =0666 ; else#endif
Signature · 1 line
2.52.0
Quoted 6 lines · Ondrej Mosnacek
The IPC sysctls implement the
ctl_table_root::permissionshook and they override the file access mode based on theCAP_CHECKPOINT_RESTOREcapability, which is being checked regardless of whether any access is actually denied or not, so if an LSM denies the capability, an audit record may be logged even when access is in fact granted.
Quoted 8 lines
It wouldn't be viable to restructure the sysctl permission logic to only check the capability when the access would be actually denied if it's not granted. Thus, do the same as in
net_ctl_permissions()(net/sysctl_net.c) - switch fromns_capable()tons_capable_noaudit(), so that the check never emits an audit record.Fixes 0889f44e2810 ("ipc: Check permissions for checkpoint_restart sysctls at open time")Signed-off-by Ondrej Mosnacek <[email protected]>
Some permission hooks already use ns_capable_noaudit. For example, pid_table_root_permissions.
I think it makes sense here also.
Quoted 38 lines
--- include/linux/capability.h | 6 ++++++ ipc/ipc_sysctl.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)include/linux/capability.h +6
-0@@ -203,6 +203,12 @@ static inline bool checkpoint_restore_ns_capable(struct user_namespace *ns)ns_capable (ns,CAP_SYS_ADMIN ); } +static inline bool checkpoint_restore_ns_capable_noaudit (struct user_namespace *ns) +{ +return ns_capable_noaudit (ns,CAP_CHECKPOINT_RESTORE ) || +ns_capable_noaudit (ns,CAP_SYS_ADMIN ); +} +/* audit system wants to get cap info from files as well */ int get_vfs_caps_from_disk(struct mnt_idmap *idmap, const struct dentry *dentry,ipc/ipc_sysctl.c +1
-1@@ -214,7 +214,7 @@ static int ipc_permissions(struct ctl_table_header *head, const struct ctl_tableif (((table->data == &ns->ids[IPC_SEM_IDS ].next_id) || (table->data == &ns->ids[IPC_MSG_IDS ].next_id) || (table->data == &ns->ids[IPC_SHM_IDS ].next_id)) && -checkpoint_restore_ns_capable (ns->user_ns)) +checkpoint_restore_ns_capable_noaudit (ns->user_ns)) mode =0666 ; else#endif Signature · 1 line
2.52.0
Signature · 1 line
Rgrds, legion
Paul Moore
maintainerQuoted 13 lines · Ondrej Mosnacek
The IPC sysctls implement the
ctl_table_root::permissionshook and they override the file access mode based on theCAP_CHECKPOINT_RESTOREcapability, which is being checked regardless of whether any access is actually denied or not, so if an LSM denies the capability, an audit record may be logged even when access is in fact granted.It wouldn't be viable to restructure the sysctl permission logic to only check the capability when the access would be actually denied if it's not granted. Thus, do the same as in
net_ctl_permissions()(net/sysctl_net.c) - switch fromns_capable()tons_capable_noaudit(), so that the check never emits an audit record.
Quoted 6 lines
Fixes 0889f44e2810 ("ipc: Check permissions for checkpoint_restart sysctls at open time")Signed-off-by Ondrej Mosnacek <[email protected]>--- include/linux/capability.h | 6 ++++++ ipc/ipc_sysctl.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
This change seems reasonable to me, but I would make sure Serge has a chance to review/ACK this patch as it has a capability impact.
Signature · 1 line
paul-moore.com
Quoted 21 lines · Paul Moore
Quoted 13 lines · Ondrej Mosnacek
The IPC sysctls implement the
ctl_table_root::permissionshook and they override the file access mode based on theCAP_CHECKPOINT_RESTOREcapability, which is being checked regardless of whether any access is actually denied or not, so if an LSM denies the capability, an audit record may be logged even when access is in fact granted.It wouldn't be viable to restructure the sysctl permission logic to only check the capability when the access would be actually denied if it's not granted. Thus, do the same as in
net_ctl_permissions()(net/sysctl_net.c) - switch fromns_capable()tons_capable_noaudit(), so that the check never emits an audit record.Quoted 6 lines
Fixes 0889f44e2810 ("ipc: Check permissions for checkpoint_restart sysctls at open time")Signed-off-by Ondrej Mosnacek <[email protected]>--- include/linux/capability.h | 6 ++++++ ipc/ipc_sysctl.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
Quoted 2 lines
This change seems reasonable to me, but I would make sure Serge has a chance to review/ACK this patch as it has a capability impact.
Thanks - looks good to me.
Paul Moore
maintainerQuoted 22 lines · Serge E. Hallyn
Quoted 21 lines · Paul Moore
Quoted 19 lines · Ondrej Mosnacek
The IPC sysctls implement the
ctl_table_root::permissionshook and they override the file access mode based on theCAP_CHECKPOINT_RESTOREcapability, which is being checked regardless of whether any access is actually denied or not, so if an LSM denies the capability, an audit record may be logged even when access is in fact granted.It wouldn't be viable to restructure the sysctl permission logic to only check the capability when the access would be actually denied if it's not granted. Thus, do the same as in
net_ctl_permissions()(net/sysctl_net.c) - switch fromns_capable()tons_capable_noaudit(), so that the check never emits an audit record.Fixes 0889f44e2810 ("ipc: Check permissions for checkpoint_restart sysctls at open time")Signed-off-by Ondrej Mosnacek <[email protected]>--- include/linux/capability.h | 6 ++++++ ipc/ipc_sysctl.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 2 lines
This change seems reasonable to me, but I would make sure Serge has a chance to review/ACK this patch as it has a capability impact.
Acked-by Serge Hallyn <[email protected]>Thanks - looks good to me.
I don't see a dedicated IPC maintainer/tree, do you want to take this via the capabilities tree Serge?
Signature · 1 line
paul-moore.com
Serge E. Hallyn
maintainerQuoted 26 lines · Paul Moore
Quoted 25 lines · Serge E. Hallyn
Quoted 23 lines · Paul Moore
Quoted 13 lines · Ondrej Mosnacek
The IPC sysctls implement the
ctl_table_root::permissionshook and they override the file access mode based on theCAP_CHECKPOINT_RESTOREcapability, which is being checked regardless of whether any access is actually denied or not, so if an LSM denies the capability, an audit record may be logged even when access is in fact granted.It wouldn't be viable to restructure the sysctl permission logic to only check the capability when the access would be actually denied if it's not granted. Thus, do the same as in
net_ctl_permissions()(net/sysctl_net.c) - switch fromns_capable()tons_capable_noaudit(), so that the check never emits an audit record.Quoted 6 lines
Fixes 0889f44e2810 ("ipc: Check permissions for checkpoint_restart sysctls at open time")Signed-off-by Ondrej Mosnacek <[email protected]>--- include/linux/capability.h | 6 ++++++ ipc/ipc_sysctl.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)This change seems reasonable to me, but I would make sure Serge has a chance to review/ACK this patch as it has a capability impact.
Quoted 6 lines
Quoted 3 lines
Acked-by Serge Hallyn <[email protected]>Thanks - looks good to me.
I don't see a dedicated IPC maintainer/tree, do you want to take this via the capabilities tree Serge?
Will do.
-serge