Skip to content

Commit 47934e0

Browse files
Congyu-Liudavem330
authored andcommitted
net: fix information leakage in /proc/net/ptype
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: 2feb27d ("[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>
1 parent fa2e1ba commit 47934e0

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,6 +2548,7 @@ struct packet_type {
25482548
struct net_device *);
25492549
bool (*id_match)(struct packet_type *ptype,
25502550
struct sock *sk);
2551+
struct net *af_packet_net;
25512552
void *af_packet_priv;
25522553
struct list_head list;
25532554
};

net/core/net-procfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
260260

261261
if (v == SEQ_START_TOKEN)
262262
seq_puts(seq, "Type Device Function\n");
263-
else if (pt->dev == NULL || dev_net(pt->dev) == seq_file_net(seq)) {
263+
else if ((!pt->af_packet_net || net_eq(pt->af_packet_net, seq_file_net(seq))) &&
264+
(!pt->dev || net_eq(dev_net(pt->dev), seq_file_net(seq)))) {
264265
if (pt->type == htons(ETH_P_ALL))
265266
seq_puts(seq, "ALL ");
266267
else

net/packet/af_packet.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,7 @@ static int fanout_add(struct sock *sk, struct fanout_args *args)
17741774
match->prot_hook.dev = po->prot_hook.dev;
17751775
match->prot_hook.func = packet_rcv_fanout;
17761776
match->prot_hook.af_packet_priv = match;
1777+
match->prot_hook.af_packet_net = read_pnet(&match->net);
17771778
match->prot_hook.id_match = match_fanout_group;
17781779
match->max_num_members = args->max_num_members;
17791780
list_add(&match->list, &fanout_list);
@@ -3353,6 +3354,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
33533354
po->prot_hook.func = packet_rcv_spkt;
33543355

33553356
po->prot_hook.af_packet_priv = sk;
3357+
po->prot_hook.af_packet_net = sock_net(sk);
33563358

33573359
if (proto) {
33583360
po->prot_hook.type = proto;

0 commit comments

Comments
 (0)