回复: [PATCH net] net: fix information leakage in /proc/net/ptype
From: Liu, Congyu
Date: Tue Jan 18 2022 - 13:53:51 EST
Thanks! That makes sense. I will send a V2 patch.
________________________________________
发件人: Eric Dumazet <edumazet@xxxxxxxxxx>
发送时间: 2022年1月18日 3:40
收件人: Liu, Congyu
抄送: David Miller; Jakub Kicinski; Yajun Deng; Willem de Bruijn; Marc Kleine-Budde; rsanger@xxxxxxxxxxx; Wang Hai; Pablo Neira Ayuso; jiapeng.chong@xxxxxxxxxxxxxxxxx; netdev; LKML
主题: Re: [PATCH net] net: fix information leakage in /proc/net/ptype
On Mon, Jan 17, 2022 at 11:01 PM Congyu Liu <liu3101@xxxxxxxxxx> wrote:
>
> 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. I believe this is minor information leakage as packet socket is
> namespace aware.
>
> Add a function pointer in `packet_type` to retrieve the net namespace
> of corresponding packet socket. In `ptype_seq_show`, if this
> function pointer is not NULL, use it to determine if certain ptype
> should be shown.
>
> Signed-off-by: Congyu Liu <liu3101@xxxxxxxxxx>
> ---
> include/linux/netdevice.h | 1 +
> net/core/net-procfs.c | 3 ++-
> net/packet/af_packet.c | 18 ++++++++++++++++++
> 3 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index 3213c7227b59..72d3601850c5 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -2548,6 +2548,7 @@ struct packet_type {
> struct net_device *);
> bool (*id_match)(struct packet_type *ptype,
> struct sock *sk);
> + struct net *(*get_net) (struct packet_type *ptype);
> void *af_packet_priv;
> struct list_head list;
> };
Patch looks fine, but the question is:
Can an af_packet socket created in netns A can be moved to netns B later ?
As the answer is probably no, it seems we could simply add a 'struct
net' pointer
in 'struct packet type', no need for a function.
Thanks.