From: Chris Mi <cmi@nvidia.com>
To: netdev@vger.kernel.org
Cc: idosch@nvidia.com, Chris Mi <cmi@nvidia.com>,
Yotam Gigi <yotam.gi@gmail.com>
Subject: [PATCH net] net: psample: Fix the netlink skb length
Date: Wed, 3 Feb 2021 11:10:28 +0800 [thread overview]
Message-ID: <20210203031028.171318-1-cmi@nvidia.com> (raw)
Currently, the netlink skb length only includes metadata and data
length. It doesn't include the psample generic netlink header length.
Fix it by adding it.
Fixes: 6ae0a6286171 ("net: Introduce psample, a new genetlink channel for packet sampling")
CC: Yotam Gigi <yotam.gi@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Chris Mi <cmi@nvidia.com>
---
net/psample/psample.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/net/psample/psample.c b/net/psample/psample.c
index 33e238c965bd..807d75f5a40f 100644
--- a/net/psample/psample.c
+++ b/net/psample/psample.c
@@ -363,6 +363,7 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
struct ip_tunnel_info *tun_info;
#endif
struct sk_buff *nl_skb;
+ int header_len;
int data_len;
int meta_len;
void *data;
@@ -381,12 +382,13 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
meta_len += psample_tunnel_meta_len(tun_info);
#endif
+ /* psample generic netlink header size */
+ header_len = nlmsg_total_size(GENL_HDRLEN + psample_nl_family.hdrsize);
data_len = min(skb->len, trunc_size);
- if (meta_len + nla_total_size(data_len) > PSAMPLE_MAX_PACKET_SIZE)
- data_len = PSAMPLE_MAX_PACKET_SIZE - meta_len - NLA_HDRLEN
+ if (header_len + meta_len + nla_total_size(data_len) > PSAMPLE_MAX_PACKET_SIZE)
+ data_len = PSAMPLE_MAX_PACKET_SIZE - header_len - meta_len - NLA_HDRLEN
- NLA_ALIGNTO;
-
- nl_skb = genlmsg_new(meta_len + nla_total_size(data_len), GFP_ATOMIC);
+ nl_skb = genlmsg_new(header_len + meta_len + nla_total_size(data_len), GFP_ATOMIC);
if (unlikely(!nl_skb))
return;
--
2.26.2
next reply other threads:[~2021-02-03 3:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-03 3:10 Chris Mi [this message]
2021-02-04 2:21 ` [PATCH net] net: psample: Fix the netlink skb length Jakub Kicinski
2021-02-04 8:47 ` Ido Schimmel
2021-02-04 9:32 ` Chris Mi
2021-02-04 9:23 ` Chris Mi
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=20210203031028.171318-1-cmi@nvidia.com \
--to=cmi@nvidia.com \
--cc=idosch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=yotam.gi@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).