From patchwork Wed Feb 3 03:10:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 12063287 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BB01C433DB for ; Wed, 3 Feb 2021 03:21:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FB5764E29 for ; Wed, 3 Feb 2021 03:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232478AbhBCDUe (ORCPT ); Tue, 2 Feb 2021 22:20:34 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:43985 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232400AbhBCDRs (ORCPT ); Tue, 2 Feb 2021 22:17:48 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from cmi@nvidia.com) with SMTP; 3 Feb 2021 05:10:59 +0200 Received: from dev-r630-03.mtbc.labs.mlnx (dev-r630-03.mtbc.labs.mlnx [10.75.205.13]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 1133AvNn017835; Wed, 3 Feb 2021 05:10:58 +0200 From: Chris Mi To: netdev@vger.kernel.org Cc: idosch@nvidia.com, Chris Mi , Yotam Gigi Subject: [PATCH net] net: psample: Fix the netlink skb length Date: Wed, 3 Feb 2021 11:10:28 +0800 Message-Id: <20210203031028.171318-1-cmi@nvidia.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Ido Schimmel Signed-off-by: Chris Mi --- 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;