Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8706157rwp; Wed, 19 Jul 2023 14:07:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlGs5FH3BFpTtI9JK6n+uzC/YQ08Ine6GrHft2Kb2nJcZsNKvStGXpPEFBzEaKlaD5g9uLW/ X-Received: by 2002:a17:906:5388:b0:98d:cd3e:c193 with SMTP id g8-20020a170906538800b0098dcd3ec193mr2611109ejo.46.1689800856412; Wed, 19 Jul 2023 14:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689800856; cv=none; d=google.com; s=arc-20160816; b=FkLUD6WoFoU7l/7RGrhQ32Fhg1DRtD2s2LTVQQYNq23Obj8fVNtzM8eX4g351CLgO3 PTAslyjmk+IndVCSwza2K3IBEdmWGmsWf0fSBzdLZe1SzBTPzjilc2Zb+MRGeYN4AmTR HZl4Bl4yegYC5PtSuOyfFAOyImCTGRVGKOjeL/u49YxUyEfO/xe248vzvfbMJ0Lqkh1p WyNllQ/EO0AR+lPHpp8N2ypflOqsxS4Ri8LDxVsKaumv3kFv7/yAbPt/7+aZ4zoIC/mV psbqLSkr5XGrtD6aPMrKuYG4pITDxKbNm20k5OESyueQxTHkghQcfLAJClX9mhq8PpUm m9Rw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KcCl97aZLH/jySxAYYmz9zHg6peUTTLBPuClan1ojrU=; fh=L25bI22Y4h2nlxYi3SiuGrikSvp5JITVFvWG3qKhvOg=; b=v5fhrlBbLtkf/mlun6ckc1lJ5SNJCxAML0GMxXALeGpgwDes7s36UlMNZbCvJrdpOp SD9bYL1LpsnreGkctp5ZpUzeAM1ViRO3iXoJVi3yVDQaANODaYCzpZWhuLmAhulFN5vh pzpWwi7OgetqsT1SvJ6dJS602XvrZRwi6h1AkZmzAKFW9XVedMiHL0hHCP9Z966JdMe+ eZhx/tFBPUqAaXgDItoh2trlt16B6Op47JyxSR7dRRIihJtOwrSebMOEyfKy7GeuTsVq eOuQ9r5ASLwbp8KJzM7GC4Fn7PnvuGeFyx+Y+MDAfrNY4ScQjOZFajAO4mrhEiwM2PX2 7beA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=Soy4kG+t; 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=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ot29-20020a170906ccdd00b00997e1a4b954si3010188ejb.25.2023.07.19.14.07.10; Wed, 19 Jul 2023 14:07:36 -0700 (PDT) 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=@oracle.com header.s=corp-2023-03-30 header.b=Soy4kG+t; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbjGSUTv (ORCPT + 99 others); Wed, 19 Jul 2023 16:19:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbjGSUTm (ORCPT ); Wed, 19 Jul 2023 16:19:42 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 606131FFA; Wed, 19 Jul 2023 13:19:30 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36JFOYUe000505; Wed, 19 Jul 2023 20:19:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=KcCl97aZLH/jySxAYYmz9zHg6peUTTLBPuClan1ojrU=; b=Soy4kG+t635UNjvVrCS0LKC0C+rrBd1CYJY8NC4Ys4Wh8yJabbLA4eS7gXX87YsnqjKj 1j5UaMmkB2jrkOfwrQGwY44HWqqUEpuzLUq52oCmctEnJs9HoasCTbkKSMdcWiAsSwRn 1Uk4A/eRdeTyxhmT0RcrLd0e5qaKuhmH7tkcKAXBwKzFOddFdd2n2PmUbmGGc8X+cm29 /PhTwZHDnWYNYJVAC+UpnqUdH1c67tIe5xUem5EaFEartTwv9R+zjbq3ieKrCLqkat4D WEa7gHuUDkuSrNHZ2vATEfwdgthMAmneNvoWz8R+8WxLp0AARqR8luTw0g2HGQ4PY6Zb aw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3run78gb91-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jul 2023 20:18:56 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 36JIXH8b038203; Wed, 19 Jul 2023 20:18:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ruhw7dwtn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jul 2023 20:18:55 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 36JKIrMc007349; Wed, 19 Jul 2023 20:18:54 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3ruhw7dwct-2; Wed, 19 Jul 2023 20:18:54 +0000 From: Anjali Kulkarni To: davem@davemloft.net Cc: Liam.Howlett@Oracle.com, akpm@linux-foundation.org, david@fries.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, zbr@ioremap.net, brauner@kernel.org, johannes@sipsolutions.net, ecree.xilinx@gmail.com, leon@kernel.org, keescook@chromium.org, socketcan@hartkopp.net, petrm@nvidia.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, anjali.k.kulkarni@oracle.com Subject: [PATCH net-next v10 1/6] netlink: Reverse the patch which removed filtering Date: Wed, 19 Jul 2023 13:18:16 -0700 Message-ID: <20230719201821.495037-2-anjali.k.kulkarni@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719201821.495037-1-anjali.k.kulkarni@oracle.com> References: <20230719201821.495037-1-anjali.k.kulkarni@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-19_14,2023-07-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 spamscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307190183 X-Proofpoint-ORIG-GUID: aYWflbuq6CDsAXCH0HXePKv1uLJ99rtf X-Proofpoint-GUID: aYWflbuq6CDsAXCH0HXePKv1uLJ99rtf X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To use filtering at the connector & cn_proc layers, we need to enable filtering in the netlink layer. This reverses the patch which removed netlink filtering - commit ID for that patch: 549017aa1bb7 (netlink: remove netlink_broadcast_filtered). Signed-off-by: Anjali Kulkarni Reviewed-by: Liam R. Howlett Acked-by: Jakub Kicinski --- include/linux/netlink.h | 5 +++++ net/netlink/af_netlink.c | 27 +++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/linux/netlink.h b/include/linux/netlink.h index 9eec3f4f5351..3a6563681b50 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -227,6 +227,11 @@ bool netlink_strict_get_check(struct sk_buff *skb); int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 portid, int nonblock); int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 portid, __u32 group, gfp_t allocation); +int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb, + __u32 portid, __u32 group, gfp_t allocation, + int (*filter)(struct sock *dsk, + struct sk_buff *skb, void *data), + void *filter_data); int netlink_set_err(struct sock *ssk, __u32 portid, __u32 group, int code); int netlink_register_notifier(struct notifier_block *nb); int netlink_unregister_notifier(struct notifier_block *nb); diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 9c9df143a2ec..6c0bcde620e8 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -1432,6 +1432,8 @@ struct netlink_broadcast_data { int delivered; gfp_t allocation; struct sk_buff *skb, *skb2; + int (*tx_filter)(struct sock *dsk, struct sk_buff *skb, void *data); + void *tx_data; }; static void do_one_broadcast(struct sock *sk, @@ -1485,6 +1487,13 @@ static void do_one_broadcast(struct sock *sk, p->delivery_failure = 1; goto out; } + + if (p->tx_filter && p->tx_filter(sk, p->skb2, p->tx_data)) { + kfree_skb(p->skb2); + p->skb2 = NULL; + goto out; + } + if (sk_filter(sk, p->skb2)) { kfree_skb(p->skb2); p->skb2 = NULL; @@ -1507,8 +1516,12 @@ static void do_one_broadcast(struct sock *sk, sock_put(sk); } -int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 portid, - u32 group, gfp_t allocation) +int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb, + u32 portid, + u32 group, gfp_t allocation, + int (*filter)(struct sock *dsk, + struct sk_buff *skb, void *data), + void *filter_data) { struct net *net = sock_net(ssk); struct netlink_broadcast_data info; @@ -1527,6 +1540,8 @@ int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 portid, info.allocation = allocation; info.skb = skb; info.skb2 = NULL; + info.tx_filter = filter; + info.tx_data = filter_data; /* While we sleep in clone, do not allow to change socket list */ @@ -1552,6 +1567,14 @@ int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 portid, } return -ESRCH; } +EXPORT_SYMBOL(netlink_broadcast_filtered); + +int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 portid, + u32 group, gfp_t allocation) +{ + return netlink_broadcast_filtered(ssk, skb, portid, group, allocation, + NULL, NULL); +} EXPORT_SYMBOL(netlink_broadcast); struct netlink_set_err_data { -- 2.41.0