* [PATCH net-next] net: ipv4: add capability check for net administration
@ 2021-07-20 1:43 cgel.zte
2021-07-20 14:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2021-07-20 1:43 UTC (permalink / raw)
To: kuba
Cc: davem, yoshfuji, dsahern, netdev, linux-kernel, Yang Yang, Zeal Robot
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.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
---
net/ipv4/devinet.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
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 */
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] net: ipv4: add capability check for net administration
2021-07-20 1:43 [PATCH net-next] net: ipv4: add capability check for net administration cgel.zte
@ 2021-07-20 14:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-07-20 14:20 UTC (permalink / raw)
To: None
Cc: kuba, davem, yoshfuji, dsahern, netdev, linux-kernel,
yang.yang29, zealci
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-20 14:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-20 1:43 [PATCH net-next] net: ipv4: add capability check for net administration cgel.zte
2021-07-20 14:20 ` patchwork-bot+netdevbpf
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).