diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index d38124bd1b94..94b648d9eaff 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 && !ns_capable(net->user_ns, CAP_NET_ADMIN)) + return -EPERM; + + ret = proc_dointvec(ctl, write, buffer, lenp, ppos); if (write && *valp != val) { - struct net *net = ctl->extra2; - if (valp != &IPV4_DEVCONF_DFLT(net, FORWARDING)) { if (!rtnl_trylock()) { /* Restore the original values before restarting */