]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
net: fix information leakage in /proc/net/ptype
authorCongyu Liu <liu3101@purdue.edu>
Tue, 18 Jan 2022 19:20:13 +0000 (14:20 -0500)
committerPaolo Pisati <paolo.pisati@canonical.com>
Thu, 3 Feb 2022 09:28:50 +0000 (10:28 +0100)
BugLink: https://bugs.launchpad.net/bugs/1959879
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>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
include/linux/netdevice.h
net/core/net-procfs.c
net/packet/af_packet.c

index ce81cc96a98d98017a02a8d1599d182d4b357e77..fba54624191a279f638419fce0644eee9c6a321d 100644 (file)
@@ -2636,6 +2636,7 @@ struct packet_type {
                                              struct net_device *);
        bool                    (*id_match)(struct packet_type *ptype,
                                            struct sock *sk);
+       struct net              *af_packet_net;
        void                    *af_packet_priv;
        struct list_head        list;
 };
index d8b9dbabd4a439137c408fb548ea058b1349c3a1..5b8016335acaf0cae143cdd15cb16b4e970f5e46 100644 (file)
@@ -260,7 +260,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
index 1bc7ef49e14876b7e18acfc90e2b3335b789d4ea..1a138e8d32d666fc1811ce62f4cfb0eb93969a10 100644 (file)
@@ -1738,6 +1738,7 @@ static int fanout_add(struct sock *sk, struct fanout_args *args)
                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;
                match->max_num_members = args->max_num_members;
                list_add(&match->list, &fanout_list);
@@ -3323,6 +3324,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;