summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorCongyu Liu <liu3101@purdue.edu>2022-01-18 14:20:13 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-02-08 18:16:26 +0100
commitc38023032a598ec6263e008d62c7f02def72d5c7 (patch)
tree0d930ebf022404f1644bec97c28b5408b7cbed8f /net
parent5ce961a393e58f924468d6d5c9e7d22f90375198 (diff)
downloadlinux-stable-c38023032a598ec6263e008d62c7f02def72d5c7.tar.gz
linux-stable-c38023032a598ec6263e008d62c7f02def72d5c7.tar.bz2
linux-stable-c38023032a598ec6263e008d62c7f02def72d5c7.zip
net: fix information leakage in /proc/net/ptype
commit 47934e06b65637c88a762d9c98329ae6e3238888 upstream. In one net namespace, after creating a packet socket without binding it to a device, users in other net namespaces can observe the new `packet_type` added by this packet socket by reading `/proc/net/ptype` file. This is minor information leakage as packet socket is namespace aware. Add a net pointer in `packet_type` to keep the net namespace of of corresponding packet socket. In `ptype_seq_show`, this net pointer must be checked when it is not NULL. Fixes: 2feb27dbe00c ("[NETNS]: Minor information leak via /proc/net/ptype file.") Signed-off-by: Congyu Liu <liu3101@purdue.edu> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net')
-rw-r--r--net/core/net-procfs.c3
-rw-r--r--net/packet/af_packet.c2
2 files changed, 4 insertions, 1 deletions
diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
index 615ccab55f38..d576517f581c 100644
--- a/net/core/net-procfs.c
+++ b/net/core/net-procfs.c
@@ -279,7 +279,8 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
if (v == SEQ_START_TOKEN)
seq_puts(seq, "Type Device Function\n");
- else if (pt->dev == NULL || dev_net(pt->dev) == seq_file_net(seq)) {
+ else if ((!pt->af_packet_net || net_eq(pt->af_packet_net, seq_file_net(seq))) &&
+ (!pt->dev || net_eq(dev_net(pt->dev), seq_file_net(seq)))) {
if (pt->type == htons(ETH_P_ALL))
seq_puts(seq, "ALL ");
else
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 3177b9320c62..d54497b57a29 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1756,6 +1756,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
match->prot_hook.dev = po->prot_hook.dev;
match->prot_hook.func = packet_rcv_fanout;
match->prot_hook.af_packet_priv = match;
+ match->prot_hook.af_packet_net = read_pnet(&match->net);
match->prot_hook.id_match = match_fanout_group;
list_add(&match->list, &fanout_list);
}
@@ -3330,6 +3331,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
po->prot_hook.func = packet_rcv_spkt;
po->prot_hook.af_packet_priv = sk;
+ po->prot_hook.af_packet_net = sock_net(sk);
if (proto) {
po->prot_hook.type = proto;