From: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
To: Liam Howlett <liam.howlett@oracle.com>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
"david@fries.net" <david@fries.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"zbr@ioremap.net" <zbr@ioremap.net>,
"brauner@kernel.org" <brauner@kernel.org>,
"johannes@sipsolutions.net" <johannes@sipsolutions.net>,
"ecree.xilinx@gmail.com" <ecree.xilinx@gmail.com>,
"leon@kernel.org" <leon@kernel.org>,
"keescook@chromium.org" <keescook@chromium.org>,
"socketcan@hartkopp.net" <socketcan@hartkopp.net>,
"petrm@nvidia.com" <petrm@nvidia.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH v5 1/6] netlink: Reverse the patch which removed filtering
Date: Thu, 1 Jun 2023 20:24:52 +0000 [thread overview]
Message-ID: <A660C134-4EAE-4CC5-9783-350C2DD93AB8@oracle.com> (raw)
In-Reply-To: <20230601175621.ugsgt2ta4c5b6wim@revolver>
> On Jun 1, 2023, at 10:56 AM, Liam Howlett <liam.howlett@oracle.com> wrote:
>
> * Anjali Kulkarni <anjali.k.kulkarni@oracle.com> [691231 23:00]:
>> 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 <anjali.k.kulkarni@oracle.com>
>> ---
>> 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);
>
> Nit, just a personal preference that if you indent with two tabs for
> function definitions, then it is clear where the code starts and you
> have more room for larger argument lists here. It also helps when
> changing the return type as you don't have to redo all the spacing.
Thanks so much - will update my code will all your review comments plus those of Jakub & Andrew, and send it out in the next revision.
Anjali
>
>> 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;
>> }
>
> new line here please.
>
>> + if (p->tx_filter && p->tx_filter(sk, p->skb2, p->tx_data)) {
>> + kfree_skb(p->skb2);
>> + p->skb2 = NULL;
>> + goto out;
>> + }
>
> new line here please.
>
> Since there are now two times that the same steps are being used for
> unrolling (yours and below). It might be better to make a new goto
> label after the successful one?
>
>> 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)
>
> Same comment here about the two tab indent.
>
>> {
>> 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
next prev parent reply other threads:[~2023-06-01 20:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-20 20:27 [PATCH v5 0/6] Process connector bug fixes & enhancements Anjali Kulkarni
2023-04-20 20:27 ` [PATCH v5 1/6] netlink: Reverse the patch which removed filtering Anjali Kulkarni
2023-06-01 17:56 ` Liam R. Howlett
2023-06-01 20:24 ` Anjali Kulkarni [this message]
2023-04-20 20:27 ` [PATCH v5 2/6] netlink: Add new netlink_release function Anjali Kulkarni
2023-06-01 17:59 ` Liam R. Howlett
2023-04-20 20:27 ` [PATCH v5 3/6] connector/cn_proc: Add filtering to fix some bugs Anjali Kulkarni
2023-06-01 18:04 ` Liam R. Howlett
2023-04-20 20:27 ` [PATCH v5 4/6] connector/cn_proc: Test code for proc connector Anjali Kulkarni
2023-04-20 20:27 ` [PATCH v5 5/6] connector/cn_proc: Performance improvements Anjali Kulkarni
2023-06-01 18:14 ` Liam R. Howlett
2023-04-20 20:27 ` [PATCH v5 6/6] connector/cn_proc: Allow non-root users access Anjali Kulkarni
2023-06-01 18:20 ` Liam R. Howlett
2023-05-25 21:39 ` [PATCH v5 0/6] Process connector bug fixes & enhancements Andrew Morton
2023-05-26 18:18 ` Anjali Kulkarni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=A660C134-4EAE-4CC5-9783-350C2DD93AB8@oracle.com \
--to=anjali.k.kulkarni@oracle.com \
--cc=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=david@fries.net \
--cc=ecree.xilinx@gmail.com \
--cc=edumazet@google.com \
--cc=johannes@sipsolutions.net \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=liam.howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=socketcan@hartkopp.net \
--cc=zbr@ioremap.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®