Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1925896pxb; Wed, 2 Feb 2022 16:08:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNtjDmiNZxmsQ8a3DGgMJZ2BeecM6sZsvSAG8NzMnPfvh1D/MV0kvfwl8RApYo1zpncQMz X-Received: by 2002:a17:902:9a4b:: with SMTP id x11mr15087565plv.138.1643846883939; Wed, 02 Feb 2022 16:08:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643846883; cv=none; d=google.com; s=arc-20160816; b=DsKKjgDnQD+UR059WpZJecX4ASaNs7yIjkvq3y/CMPqDEReuakAm9Kc7hWf1rNFnHi euxl/QZJRrVvTkbJyticOTb2IYjWeIQuSRTB5iv9na5NM7tj+EpqAK4jgbyD8WLlMbkS c3et1NOt8l4brf9SNjgTffxLA8dBh86AoWXoUa3zLhf5rUVpTy1Y46a8WlOrlnDBu5Gj 65TLLtYNS1w1t1uhUfgvDKhI1W3IWvIZNHQ37UnDg61Kp96j0KRbDpXvox+oK1nI9ZlJ SWG4ompW1DU+jxgTDqb7YcsxLk2AwausyUtsdZn0KuqoIVVunAWngK62OQxZ/ixgHAC+ SQIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+cwV/vJmfqU+nn4zh0CkCDkhVQqjsmjEvLsugE5dtUU=; b=zSZ/mTxrp9Uo+Y7DF05IL+3duZTsi8f/P9+RUzQBcQ+yrPo/5wfco0tW7TR4MWdScF 91hDDbME6rIkGt6SScmtc2yAsm6QCaW12mAwi5LzLdbWzEYwmcsjYkD2tAynVkW/RFXY DjQ8kNKuQd7WLLOe7KECa4FtDIa+Xi4V4uselFlW6pmR+fFlxxz+I1HMzNlqv4JqXZdR FYGnoWEH6xKniejiuUG0aKaY+wo16Rti2NiJjifB0uPWbBq/2xBI2fU7xWREpKEys9F5 F1LJFVHMv4fcYXN5recHhR1mMOaJfEWb+owqsKbmSkYMsEaXuc32FUSlgPJdwljPqWjN qIhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u281vfBn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m16si20105591pfc.308.2022.02.02.16.07.52; Wed, 02 Feb 2022 16:08:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u281vfBn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241924AbiBASRf (ORCPT + 99 others); Tue, 1 Feb 2022 13:17:35 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:50984 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241758AbiBASRT (ORCPT ); Tue, 1 Feb 2022 13:17:19 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id E18B8CE1A62; Tue, 1 Feb 2022 18:17:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A547FC340EC; Tue, 1 Feb 2022 18:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643739436; bh=wLrtGiR/jBkZrHg5VUQFI2O99lJ5Cz8mzTnT21nK2xM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u281vfBn9Xra3mUWTeiONgvABXnoZlK6RBXUZLsq9Jtv3o9p5Lrgu/4IFfMldDz1G RiC6zciD34TjUbvR9RS5Knj8RaWEjixhElyQZvhTgx43hMKDXlRx8VXZclJJiyY40o +9wReHROMz2EFpVytKa1ZY51aHhA362ZJLOCT4jQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Congyu Liu , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 15/25] net: fix information leakage in /proc/net/ptype Date: Tue, 1 Feb 2022 19:16:39 +0100 Message-Id: <20220201180822.645522157@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220201180822.148370751@linuxfoundation.org> References: <20220201180822.148370751@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Congyu Liu 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 Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- include/linux/netdevice.h | 1 + net/core/net-procfs.c | 3 ++- net/packet/af_packet.c | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2055,6 +2055,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; }; --- a/net/core/net-procfs.c +++ b/net/core/net-procfs.c @@ -277,7 +277,8 @@ static int ptype_seq_show(struct seq_fil 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 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1709,6 +1709,7 @@ static int fanout_add(struct sock *sk, u 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); } @@ -3167,6 +3168,7 @@ static int packet_create(struct net *net 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;