Message ID | 20210720014328.378868-1-yang.yang29@zte.com.cn (mailing list archive) |
---|---|
State | Accepted |
Commit | 8292d7f6e8712381a828eac2a19a610ce680c4dd |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net-next] net: ipv4: add capability check for net administration | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for net-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | success | CCed 5 of 5 maintainers |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 1 this patch: 1 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 18 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 1 this patch: 1 |
netdev/header_inline | success | Link |
Hello: This patch was applied to netdev/net-next.git (refs/heads/master): On Mon, 19 Jul 2021 18:43:28 -0700 you wrote: > From: Yang Yang <yang.yang29@zte.com.cn> > > Root in init user namespace can modify /proc/sys/net/ipv4/ip_forward > without CAP_NET_ADMIN, this doesn't follow the principle of > capabilities. For example, let's take a look at netdev_store(), > root can't modify netdev attribute without CAP_NET_ADMIN. > So let's keep the consistency of permission check logic. > > [...] Here is the summary with links: - [net-next] net: ipv4: add capability check for net administration https://git.kernel.org/netdev/net-next/c/8292d7f6e871 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 73721a4448bd..6238ab2dd3d1 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -2424,11 +2424,15 @@ static int devinet_sysctl_forward(struct ctl_table *ctl, int write, int *valp = ctl->data; int val = *valp; loff_t pos = *ppos; - int ret = proc_dointvec(ctl, write, buffer, lenp, ppos); + struct net *net = ctl->extra2; + int ret; - if (write && *valp != val) { - struct net *net = ctl->extra2; + if (write && !ns_capable(net->user_ns, CAP_NET_ADMIN)) + return -EPERM; + + ret = proc_dointvec(ctl, write, buffer, lenp, ppos); + if (write && *valp != val) { if (valp != &IPV4_DEVCONF_DFLT(net, FORWARDING)) { if (!rtnl_trylock()) { /* Restore the original values before restarting */