Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1767544rwl; Fri, 31 Mar 2023 16:56:40 -0700 (PDT) X-Google-Smtp-Source: AKy350ZtDmQUNp2iuJvkA95t/R8U3jJ3S1yTvB05LX1ISezfzqa4+J1jBJsfxw4npt2eZ4vjbFdi X-Received: by 2002:a17:906:1001:b0:93f:e5e4:8c13 with SMTP id 1-20020a170906100100b0093fe5e48c13mr18980379ejm.5.1680307000543; Fri, 31 Mar 2023 16:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680307000; cv=none; d=google.com; s=arc-20160816; b=bSwtlaRb6Jryh3xfSzccMPbbEjTEsVukeNLgPNG7mbHYioBhUWL4jUsuQWzcoY2d15 6rX4kFHqclyg3EM9PDPupvP2W/N79YSm6E2UIpYQAXN3bbLhF6t51xIAmtJzzYC8RZIO VlkS0/nhWKJmkLwUlrtT2+bpCOSpspbsQbXX+r9yucJX/0mrZYxqYnfK4AT7PcPq3hkq ECsRmhfEPmwIAJoGReRK/eZUTIO2ee0whsgTzlLg9H0lXANxK8ru8JUb1kct+RINyfvT pispOSZxvy76/P8oMTht1NQgzlO0r1nxCpmbnmYKHQ9WRPa5Xcf/PEwcMfhgOD9BkjpR ckMg== 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=JLjZZTYyJYJMe3QiAlLr02+MhgbjP8RiniXG97TsRPo=; b=yRDcpGA0rxKy5LL5CAwLDjiu/cMUq0dDl0oaw2ghdBvkcV0+bbtFHXQ3cOBljW/54y IydhF3XHp9Fa7tkSRJXQV13Qp1GlCaVqmP8qqx8aZ1gPCKIKbKUd90K+FLHi6U9xJAyp hgHigtye5lPV0S/JDiijj9ki3wPcgRteR2+ggCv1hAq2nWsxncippEoseBE3lDacxjCs jc58cweDFKIpfEkxIZR5womOXrDvtMoxsBxVKNmOcQkMYywAGjdXSC/nPsSh3hIhQxq2 M2fZ2RZ2vXotpnk0uTZpcjk8M9RFc/HBFfE5PwnjDnC6wPr6ZhbiOuFPsprF/UrNl+e8 YWqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b="dOg9I/vH"; 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 w3-20020a17090652c300b00932f1744dcfsi2883398ejn.54.2023.03.31.16.56.15; Fri, 31 Mar 2023 16:56:40 -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-2022-7-12 header.b="dOg9I/vH"; 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 S233343AbjCaXz4 (ORCPT + 99 others); Fri, 31 Mar 2023 19:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233179AbjCaXzw (ORCPT ); Fri, 31 Mar 2023 19:55:52 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B8B71C1F9; Fri, 31 Mar 2023 16:55:51 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32VKr7Ib014473; Fri, 31 Mar 2023 23:55:34 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-2022-7-12; bh=JLjZZTYyJYJMe3QiAlLr02+MhgbjP8RiniXG97TsRPo=; b=dOg9I/vHygleuC9XF2Ko/PVAHm3hsqvks0pUmM+K0yWk35jzdlyJIrEHx7Ucl/6rpui0 Ny3ZE18Bobin6MJwEy5xgGbyt9sWdgbNOVEuYfAJe4wg5NWDYW/ZDRCQkM38L8gXDzb/ Rmi7FzCOYlIFuYO+bWATwN3d1Wf/+VcfxeC2KpH0QRm58s8GZgEBwrciicwyanWWGO58 nL1dpzbBn9kQtnr5J2r5XE2nWk+UXPYjJxJYpFZOO3V/fUGW7t4FoAUtjNonJmRBaaIN NrArgXbBT7AMXZMQ7SYI2EHqX7u72ROn/7f9uxkMSxg3gk4l0XFncS4OmIbzwLq5mrex /w== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pmqbyy9cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 31 Mar 2023 23:55:34 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32VMNgYL023539; Fri, 31 Mar 2023 23:55:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3phqdkm2qm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 31 Mar 2023 23:55:33 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32VNtUIb019347; Fri, 31 Mar 2023 23:55:32 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3phqdkm2p9-2; Fri, 31 Mar 2023 23:55:32 +0000 From: Anjali Kulkarni To: davem@davemloft.net Cc: 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 v4 1/6] netlink: Reverse the patch which removed filtering Date: Fri, 31 Mar 2023 16:55:23 -0700 Message-Id: <20230331235528.1106675-2-anjali.k.kulkarni@oracle.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230331235528.1106675-1-anjali.k.kulkarni@oracle.com> References: <20230331235528.1106675-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.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303310196 X-Proofpoint-GUID: vFnbKuzHejwMqL3iUDgiwMtJIAGOo52J X-Proofpoint-ORIG-GUID: vFnbKuzHejwMqL3iUDgiwMtJIAGOo52J X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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. Signed-off-by: Anjali Kulkarni --- include/linux/netlink.h | 5 +++++ net/netlink/af_netlink.c | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/linux/netlink.h b/include/linux/netlink.h index c43ac7690eca..866bbc5a4c8d 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -206,6 +206,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 c64277659753..003c7e6ec9be 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,11 @@ 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 +1514,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 +1538,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 +1565,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.40.0