net: fix information leakage in /proc/net/ptype
authorCongyu Liu <liu3101@purdue.edu>
Tue, 18 Jan 2022 19:20:13 +0000 (14:20 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 Feb 2022 17:15:27 +0000 (18:15 +0100)
commitbe1ca30331c7923c6f376610c1bd6059be9b1908
treea451519adb70595e9584e387d41f4f35f9e0fc1c
parentd32a15cbc0104a6882cfec5d0c4bcec720bdd9d1
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>
include/linux/netdevice.h
net/core/net-procfs.c
net/packet/af_packet.c