* [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl @ 2016-05-06 23:04 Tyler Hicks 2016-05-06 23:04 ` [PATCH 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Tyler Hicks @ 2016-05-06 23:04 UTC (permalink / raw) To: linux-security-module, netdev, linux-kernel Cc: Serge Hallyn, David S . Miller This pair of patches does away with what I believe is a useless denial audit message when a privileged process initially accesses a net sysctl. The bug was first discovered when running Go applications under AppArmor confinement. It can be triggered like so: $ echo "profile test { file, }" | sudo apparmor_parser -rq Once the profile is loaded, invoke Go as root under confinement: $ sudo aa-exec -p test -- go version go version go1.6.1 linux/amd64 Here's the denial: audit: type=1400 audit(1462575436.832:29): apparmor="DENIED" operation="capable" profile="test" pid=1157 comm="go" capability=12 capname="net_admin" The reproducer in minimal form is: $ sudo aa-exec -p test -- cat /proc/sys/net/core/somaxconn 128 The denial: audit: type=1400 audit(1462575670.000:29): apparmor="DENIED" operation="capable" profile="test" pid=1161 comm="cat" capability=12 capname="net_admin" Thanks! Tyler ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] kernel: Add noaudit variant of ns_capable() 2016-05-06 23:04 [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks @ 2016-05-06 23:04 ` Tyler Hicks 2016-05-09 4:23 ` Serge Hallyn 2016-05-06 23:04 ` [PATCH 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks 2016-05-09 3:56 ` [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl David Miller 2 siblings, 1 reply; 9+ messages in thread From: Tyler Hicks @ 2016-05-06 23:04 UTC (permalink / raw) To: linux-security-module, netdev, linux-kernel Cc: Serge Hallyn, David S . Miller When checking the current cred for a capability in a specific user namespace, it isn't always desirable to have the LSMs audit the check. This patch adds a noaudit variant of ns_capable() for when those situations arise. The common logic between ns_capable() and the new ns_capable_noaudit() is moved into a single, shared function to keep duplicated code to a minimum and ease maintainability. Signed-off-by: Tyler Hicks <tyhicks@canonical.com> --- include/linux/capability.h | 5 +++++ kernel/capability.c | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/include/linux/capability.h b/include/linux/capability.h index 00690ff..5f3c63d 100644 --- a/include/linux/capability.h +++ b/include/linux/capability.h @@ -206,6 +206,7 @@ extern bool has_ns_capability_noaudit(struct task_struct *t, struct user_namespace *ns, int cap); extern bool capable(int cap); extern bool ns_capable(struct user_namespace *ns, int cap); +extern bool ns_capable_noaudit(struct user_namespace *ns, int cap); #else static inline bool has_capability(struct task_struct *t, int cap) { @@ -233,6 +234,10 @@ static inline bool ns_capable(struct user_namespace *ns, int cap) { return true; } +static inline bool ns_capable_noaudit(struct user_namespace *ns, int cap) +{ + return true; +} #endif /* CONFIG_MULTIUSER */ extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap); extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap); diff --git a/kernel/capability.c b/kernel/capability.c index 45432b5..00411c8 100644 --- a/kernel/capability.c +++ b/kernel/capability.c @@ -361,6 +361,24 @@ bool has_capability_noaudit(struct task_struct *t, int cap) return has_ns_capability_noaudit(t, &init_user_ns, cap); } +static bool ns_capable_common(struct user_namespace *ns, int cap, bool audit) +{ + int capable; + + if (unlikely(!cap_valid(cap))) { + pr_crit("capable() called with invalid cap=%u\n", cap); + BUG(); + } + + capable = audit ? security_capable(current_cred(), ns, cap) : + security_capable_noaudit(current_cred(), ns, cap); + if (capable == 0) { + current->flags |= PF_SUPERPRIV; + return true; + } + return false; +} + /** * ns_capable - Determine if the current task has a superior capability in effect * @ns: The usernamespace we want the capability in @@ -374,19 +392,27 @@ bool has_capability_noaudit(struct task_struct *t, int cap) */ bool ns_capable(struct user_namespace *ns, int cap) { - if (unlikely(!cap_valid(cap))) { - pr_crit("capable() called with invalid cap=%u\n", cap); - BUG(); - } - - if (security_capable(current_cred(), ns, cap) == 0) { - current->flags |= PF_SUPERPRIV; - return true; - } - return false; + return ns_capable_common(ns, cap, true); } EXPORT_SYMBOL(ns_capable); +/** + * ns_capable_noaudit - Determine if the current task has a superior capability + * (unaudited) in effect + * @ns: The usernamespace we want the capability in + * @cap: The capability to be tested for + * + * Return true if the current task has the given superior capability currently + * available for use, false if not. + * + * This sets PF_SUPERPRIV on the task if the capability is available on the + * assumption that it's about to be used. + */ +bool ns_capable_noaudit(struct user_namespace *ns, int cap) +{ + return ns_capable_common(ns, cap, false); +} +EXPORT_SYMBOL(ns_capable_noaudit); /** * capable - Determine if the current task has a superior capability in effect -- 2.7.4 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] kernel: Add noaudit variant of ns_capable() 2016-05-06 23:04 ` [PATCH 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks @ 2016-05-09 4:23 ` Serge Hallyn 0 siblings, 0 replies; 9+ messages in thread From: Serge Hallyn @ 2016-05-09 4:23 UTC (permalink / raw) To: Tyler Hicks Cc: linux-security-module, netdev, linux-kernel, Serge Hallyn, David S . Miller Quoting Tyler Hicks (tyhicks@canonical.com): > When checking the current cred for a capability in a specific user > namespace, it isn't always desirable to have the LSMs audit the check. > This patch adds a noaudit variant of ns_capable() for when those > situations arise. > > The common logic between ns_capable() and the new ns_capable_noaudit() > is moved into a single, shared function to keep duplicated code to a > minimum and ease maintainability. > > Signed-off-by: Tyler Hicks <tyhicks@canonical.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com> > --- > include/linux/capability.h | 5 +++++ > kernel/capability.c | 46 ++++++++++++++++++++++++++++++++++++---------- > 2 files changed, 41 insertions(+), 10 deletions(-) > > diff --git a/include/linux/capability.h b/include/linux/capability.h > index 00690ff..5f3c63d 100644 > --- a/include/linux/capability.h > +++ b/include/linux/capability.h > @@ -206,6 +206,7 @@ extern bool has_ns_capability_noaudit(struct task_struct *t, > struct user_namespace *ns, int cap); > extern bool capable(int cap); > extern bool ns_capable(struct user_namespace *ns, int cap); > +extern bool ns_capable_noaudit(struct user_namespace *ns, int cap); > #else > static inline bool has_capability(struct task_struct *t, int cap) > { > @@ -233,6 +234,10 @@ static inline bool ns_capable(struct user_namespace *ns, int cap) > { > return true; > } > +static inline bool ns_capable_noaudit(struct user_namespace *ns, int cap) > +{ > + return true; > +} > #endif /* CONFIG_MULTIUSER */ > extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap); > extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap); > diff --git a/kernel/capability.c b/kernel/capability.c > index 45432b5..00411c8 100644 > --- a/kernel/capability.c > +++ b/kernel/capability.c > @@ -361,6 +361,24 @@ bool has_capability_noaudit(struct task_struct *t, int cap) > return has_ns_capability_noaudit(t, &init_user_ns, cap); > } > > +static bool ns_capable_common(struct user_namespace *ns, int cap, bool audit) > +{ > + int capable; > + > + if (unlikely(!cap_valid(cap))) { > + pr_crit("capable() called with invalid cap=%u\n", cap); > + BUG(); > + } > + > + capable = audit ? security_capable(current_cred(), ns, cap) : > + security_capable_noaudit(current_cred(), ns, cap); > + if (capable == 0) { > + current->flags |= PF_SUPERPRIV; > + return true; > + } > + return false; > +} > + > /** > * ns_capable - Determine if the current task has a superior capability in effect > * @ns: The usernamespace we want the capability in > @@ -374,19 +392,27 @@ bool has_capability_noaudit(struct task_struct *t, int cap) > */ > bool ns_capable(struct user_namespace *ns, int cap) > { > - if (unlikely(!cap_valid(cap))) { > - pr_crit("capable() called with invalid cap=%u\n", cap); > - BUG(); > - } > - > - if (security_capable(current_cred(), ns, cap) == 0) { > - current->flags |= PF_SUPERPRIV; > - return true; > - } > - return false; > + return ns_capable_common(ns, cap, true); > } > EXPORT_SYMBOL(ns_capable); > > +/** > + * ns_capable_noaudit - Determine if the current task has a superior capability > + * (unaudited) in effect > + * @ns: The usernamespace we want the capability in > + * @cap: The capability to be tested for > + * > + * Return true if the current task has the given superior capability currently > + * available for use, false if not. > + * > + * This sets PF_SUPERPRIV on the task if the capability is available on the > + * assumption that it's about to be used. > + */ > +bool ns_capable_noaudit(struct user_namespace *ns, int cap) > +{ > + return ns_capable_common(ns, cap, false); > +} > +EXPORT_SYMBOL(ns_capable_noaudit); > > /** > * capable - Determine if the current task has a superior capability in effect > -- > 2.7.4 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions 2016-05-06 23:04 [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks 2016-05-06 23:04 ` [PATCH 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks @ 2016-05-06 23:04 ` Tyler Hicks 2016-05-09 4:24 ` Serge Hallyn 2016-05-09 3:56 ` [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl David Miller 2 siblings, 1 reply; 9+ messages in thread From: Tyler Hicks @ 2016-05-06 23:04 UTC (permalink / raw) To: linux-security-module, netdev, linux-kernel Cc: Serge Hallyn, David S . Miller The capability check should not be audited since it is only being used to determine the inode permissions. A failed check does not indicate a violation of security policy but, when an LSM is enabled, a denial audit message was being generated. The denial audit message caused confusion for some application authors because root-running Go applications always triggered the denial. To prevent this confusion, the capability check in net_ctl_permissions() is switched to the noaudit variant. BugLink: https://launchpad.net/bugs/1465724 Signed-off-by: Tyler Hicks <tyhicks@canonical.com> --- net/sysctl_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sysctl_net.c b/net/sysctl_net.c index ed98c1f..46a71c7 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head, kgid_t root_gid = make_kgid(net->user_ns, 0); /* Allow network administrator to have same access as root. */ - if (ns_capable(net->user_ns, CAP_NET_ADMIN) || + if (ns_capable_noaudit(net->user_ns, CAP_NET_ADMIN) || uid_eq(root_uid, current_euid())) { int mode = (table->mode >> 6) & 7; return (mode << 6) | (mode << 3) | mode; -- 2.7.4 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions 2016-05-06 23:04 ` [PATCH 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks @ 2016-05-09 4:24 ` Serge Hallyn 0 siblings, 0 replies; 9+ messages in thread From: Serge Hallyn @ 2016-05-09 4:24 UTC (permalink / raw) To: Tyler Hicks Cc: linux-security-module, netdev, linux-kernel, Serge Hallyn, David S . Miller Quoting Tyler Hicks (tyhicks@canonical.com): > The capability check should not be audited since it is only being used > to determine the inode permissions. A failed check does not indicate a > violation of security policy but, when an LSM is enabled, a denial audit > message was being generated. > > The denial audit message caused confusion for some application authors > because root-running Go applications always triggered the denial. To > prevent this confusion, the capability check in net_ctl_permissions() is > switched to the noaudit variant. > > BugLink: https://launchpad.net/bugs/1465724 > > Signed-off-by: Tyler Hicks <tyhicks@canonical.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com> > --- > net/sysctl_net.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/sysctl_net.c b/net/sysctl_net.c > index ed98c1f..46a71c7 100644 > --- a/net/sysctl_net.c > +++ b/net/sysctl_net.c > @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head, > kgid_t root_gid = make_kgid(net->user_ns, 0); > > /* Allow network administrator to have same access as root. */ > - if (ns_capable(net->user_ns, CAP_NET_ADMIN) || > + if (ns_capable_noaudit(net->user_ns, CAP_NET_ADMIN) || > uid_eq(root_uid, current_euid())) { > int mode = (table->mode >> 6) & 7; > return (mode << 6) | (mode << 3) | mode; > -- > 2.7.4 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl 2016-05-06 23:04 [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks 2016-05-06 23:04 ` [PATCH 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks 2016-05-06 23:04 ` [PATCH 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks @ 2016-05-09 3:56 ` David Miller 2016-05-17 14:13 ` Tyler Hicks 2 siblings, 1 reply; 9+ messages in thread From: David Miller @ 2016-05-09 3:56 UTC (permalink / raw) To: tyhicks; +Cc: linux-security-module, netdev, linux-kernel, serge.hallyn From: Tyler Hicks <tyhicks@canonical.com> Date: Fri, 6 May 2016 18:04:12 -0500 > This pair of patches does away with what I believe is a useless denial > audit message when a privileged process initially accesses a net sysctl. The LSM folks can apply this if they agree with you. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl 2016-05-09 3:56 ` [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl David Miller @ 2016-05-17 14:13 ` Tyler Hicks 2016-06-02 16:30 ` Tyler Hicks 0 siblings, 1 reply; 9+ messages in thread From: Tyler Hicks @ 2016-05-17 14:13 UTC (permalink / raw) To: jmorris Cc: David Miller, linux-security-module, netdev, linux-kernel, serge.hallyn [-- Attachment #1.1: Type: text/plain, Size: 427 bytes --] On 05/08/2016 10:56 PM, David Miller wrote: > From: Tyler Hicks <tyhicks@canonical.com> > Date: Fri, 6 May 2016 18:04:12 -0500 > >> This pair of patches does away with what I believe is a useless denial >> audit message when a privileged process initially accesses a net sysctl. > > The LSM folks can apply this if they agree with you. Hi James - Could you pick up these two bug fix patches? Thanks! Tyler [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl 2016-05-17 14:13 ` Tyler Hicks @ 2016-06-02 16:30 ` Tyler Hicks 2016-06-03 1:00 ` James Morris 0 siblings, 1 reply; 9+ messages in thread From: Tyler Hicks @ 2016-06-02 16:30 UTC (permalink / raw) To: jmorris Cc: David Miller, linux-security-module, netdev, linux-kernel, serge.hallyn [-- Attachment #1.1: Type: text/plain, Size: 579 bytes --] On 05/17/2016 09:13 AM, Tyler Hicks wrote: > On 05/08/2016 10:56 PM, David Miller wrote: >> From: Tyler Hicks <tyhicks@canonical.com> >> Date: Fri, 6 May 2016 18:04:12 -0500 >> >>> This pair of patches does away with what I believe is a useless denial >>> audit message when a privileged process initially accesses a net sysctl. >> >> The LSM folks can apply this if they agree with you. > > Hi James - Could you pick up these two bug fix patches? Thanks! Hello - Just checking in again to see if you plan on taking these through the security tree? Tyler [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl 2016-06-02 16:30 ` Tyler Hicks @ 2016-06-03 1:00 ` James Morris 0 siblings, 0 replies; 9+ messages in thread From: James Morris @ 2016-06-03 1:00 UTC (permalink / raw) To: Tyler Hicks Cc: David Miller, linux-security-module, netdev, linux-kernel, serge.hallyn On Thu, 2 Jun 2016, Tyler Hicks wrote: > On 05/17/2016 09:13 AM, Tyler Hicks wrote: > > On 05/08/2016 10:56 PM, David Miller wrote: > >> From: Tyler Hicks <tyhicks@canonical.com> > >> Date: Fri, 6 May 2016 18:04:12 -0500 > >> > >>> This pair of patches does away with what I believe is a useless denial > >>> audit message when a privileged process initially accesses a net sysctl. > >> > >> The LSM folks can apply this if they agree with you. > > > > Hi James - Could you pick up these two bug fix patches? Thanks! > > Hello - Just checking in again to see if you plan on taking these > through the security tree? Sure, please resend. -- James Morris <jmorris@namei.org> ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-06-03 1:00 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-05-06 23:04 [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl Tyler Hicks 2016-05-06 23:04 ` [PATCH 1/2] kernel: Add noaudit variant of ns_capable() Tyler Hicks 2016-05-09 4:23 ` Serge Hallyn 2016-05-06 23:04 ` [PATCH 2/2] net: Use ns_capable_noaudit() when determining net sysctl permissions Tyler Hicks 2016-05-09 4:24 ` Serge Hallyn 2016-05-09 3:56 ` [PATCH 0/2] Quiet noisy LSM denial when accessing net sysctl David Miller 2016-05-17 14:13 ` Tyler Hicks 2016-06-02 16:30 ` Tyler Hicks 2016-06-03 1:00 ` James Morris
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).