Message ID | 20231211025927.233449-1-chentao@kylinos.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6803843vqy; Sun, 10 Dec 2023 18:59:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSMB/o2q8PRsrylgHu22jb01A6XuNAE7Mdzv36tAiUeHbMI1EkchZEMB+oM06d00xuuVgg X-Received: by 2002:a05:6830:18d0:b0:6d9:f5f6:dc9d with SMTP id v16-20020a05683018d000b006d9f5f6dc9dmr3172363ote.73.1702263598030; Sun, 10 Dec 2023 18:59:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702263597; cv=none; d=google.com; s=arc-20160816; b=gxDATAIjGOs1VCx1Z4Grv6a5A8hinQHG00NtoMU1VRVy3VJ318/40LWNc6w+YBpvxT Wce7Imoyn34t7jXGSK3GvS+5cVsZlvZBJZiJRirkzS+HyfU9S2iu34Q+/urpidMr+trH XEj83OQ7atePApo4vzYc2JT57rGMlXTt31vofgxWQDQJ/cSqXsF9VbkZ0j1eoz6my4FD RVnYdfjwRzc4elRe3JJBYlfkfktRIxSOm9WDMG6lynqLMQltGMEPU+66EGi1hXSG2jhy /HLxkH4xgYKt8xwTv7pBpxuQy3zOjI6Bb6FzZ3QzYgdBoKjAPhnSQKwICLSC8eLn3rqg z2yw== 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 :message-id:date:subject:cc:to:from; bh=uogfaX9VHI7SqZmmGTRoaY28x7c0ryHA0O9azwdMUpY=; fh=BGRxrkfGVuH1vwaTE7h7o0qAEHz+H7n7hzW6m74zBa0=; b=kRdJlQJkx731OgoovO2AcgdmHnwFLsgE9vyxPY5TESiKFtKgNZAUGVgbE2dtT+1lhm QsPjkpTEwT4PH2NcGacWjnD3Wx0FIPW8DxHZqfxDk4WMAEg5iypjcFxb9zg7l702WtzZ XHSaCr7JexVDed0PmbBSr44fneZgejd30Ivx8lePdaX23HuejM0ScxGHF2WGiK4DplNt I27ftnUIqJh6m5krBP7lwRhnTqEiy/7Y6JOHYSSOjnoQ2c/xyBfr5blUXekMFdZukLac h/t9YYGAmeUd3Ju4NbuXXpwisaI/X/dXODQ94FDrQXZ03xtgJx9EVb3k4SB2O4bELqI1 2VRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id m5-20020a635805000000b005c2791fedb4si5345047pgb.21.2023.12.10.18.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 18:59:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id C4591805E11E; Sun, 10 Dec 2023 18:59:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbjLKC7p (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Sun, 10 Dec 2023 21:59:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjLKC7o (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 10 Dec 2023 21:59:44 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0327ECE; Sun, 10 Dec 2023 18:59:49 -0800 (PST) X-UUID: 0b105c8e154d4308be340be35614f20c-20231211 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33,REQID:19a20f34-c316-4582-9f89-476ca1073edf,IP:5,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-10 X-CID-INFO: VERSION:1.1.33,REQID:19a20f34-c316-4582-9f89-476ca1073edf,IP:5,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:-10 X-CID-META: VersionHash:364b77b,CLOUDID:931283fd-4a48-46e2-b946-12f04f20af8c,B ulkID:231211105935IA61I4Z6,BulkQuantity:0,Recheck:0,SF:38|24|17|19|44|66|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS X-UUID: 0b105c8e154d4308be340be35614f20c-20231211 X-User: chentao@kylinos.cn Received: from vt.. [(116.128.244.169)] by mailgw (envelope-from <chentao@kylinos.cn>) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1052257917; Mon, 11 Dec 2023 10:59:34 +0800 From: Kunwu Chan <chentao@kylinos.cn> To: jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: jacob.e.keller@intel.com, przemyslaw.kitszel@intel.com, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan <chentao@kylinos.cn>, Kunwu Chan <kunwu.chan@hotmail.com> Subject: [PATCH] iavf: Fix null pointer dereference in iavf_print_link_message Date: Mon, 11 Dec 2023 10:59:27 +0800 Message-Id: <20231211025927.233449-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 10 Dec 2023 18:59:56 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784952754204800849 X-GMAIL-MSGID: 1784952754204800849 |
Series |
iavf: Fix null pointer dereference in iavf_print_link_message
|
|
Commit Message
Kunwu Chan
Dec. 11, 2023, 2:59 a.m. UTC
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.
Fixes: 1978d3ead82c ("intel: fix string truncation warnings")
Cc: Kunwu Chan <kunwu.chan@hotmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On Mon, 11 Dec 2023 10:59:27 +0800 Kunwu Chan wrote: > kasprintf() returns a pointer to dynamically allocated memory > which can be NULL upon failure. > > Fixes: 1978d3ead82c ("intel: fix string truncation warnings") No need for the allocation here, print to a buffer on the stack.
On 12/12/2023 1:28 PM, Jakub Kicinski wrote: > On Mon, 11 Dec 2023 10:59:27 +0800 Kunwu Chan wrote: >> kasprintf() returns a pointer to dynamically allocated memory >> which can be NULL upon failure. >> >> Fixes: 1978d3ead82c ("intel: fix string truncation warnings") > > No need for the allocation here, print to a buffer on the stack. Sure, but I think that just takes us full circle back to where we started. reverting this to the previous code will add back W=1 warnings. The whole point of the commit mentioned above was to get a reasonable implementation that won't cause string truncation warnings. Is there some trick I don't know about to get an allocation which will not trigger snprintf and friends to print warnings from -Wformat-truncation > drivers/net/ethernet/intel/iavf/iavf_virtchnl.c:1425:60: warning: ‘%s’ directive output may be truncated writing 4 bytes into a region of size between 1 and 11 [-Wformat-truncation=] > drivers/net/ethernet/intel/iavf/iavf_virtchnl.c:1425:17: note: ‘snprintf’ output between 7 and 17 bytes into a destination of size 13 However the original warnings were for "%s" in strings. There should be a good way, but I don't know it so could use some help. -Jesse
On Tue, 12 Dec 2023 15:05:19 -0800 Jesse Brandeburg wrote: > On 12/12/2023 1:28 PM, Jakub Kicinski wrote: > > On Mon, 11 Dec 2023 10:59:27 +0800 Kunwu Chan wrote: > >> kasprintf() returns a pointer to dynamically allocated memory > >> which can be NULL upon failure. > >> > >> Fixes: 1978d3ead82c ("intel: fix string truncation warnings") > > > > No need for the allocation here, print to a buffer on the stack. > > Sure, but I think that just takes us full circle back to where we > started. reverting this to the previous code will add back W=1 warnings. > > The whole point of the commit mentioned above was to get a reasonable > implementation that won't cause string truncation warnings. Is there > some trick I don't know about to get an allocation which will not > trigger snprintf and friends to print warnings from -Wformat-truncation Hm, it'd be nice if there was a flavor of snprintf which explicitly doesn't trigger this warning. Or perhaps a marking for the output buffer that says "truncation OK". Absent that, can we print to a buffer on the stack and copy? The link message is probably meh, but automation may get quite confused if a NIC suddenly stops reporting FW version..
Thanks for your reply. Sure, the only thing 'iavf_print_link_message' do is to print a msg by netdev_info. The 'iavf_virtchnl_completion' assume that no errors will be returned. Whether we could just execute 'netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed? speed :"");' when 'speed' is null. Before commit '1978d3ead82c8', the buffer size is '#define IAVF_MAX_SPEED_STRLEN 13', whether we could use a bigger buffer size to avoid a null pointer. Such as '#define IAVF_MAX_SPEED_STRLEN 48'. On 2023/12/13 05:28, Jakub Kicinski wrote: > On Mon, 11 Dec 2023 10:59:27 +0800 Kunwu Chan wrote: >> kasprintf() returns a pointer to dynamically allocated memory >> which can be NULL upon failure. >> >> Fixes: 1978d3ead82c ("intel: fix string truncation warnings") > > No need for the allocation here, print to a buffer on the stack.
diff --git a/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c b/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c index 64c4443dbef9..1b50d351f28b 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +++ b/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c @@ -1444,6 +1444,8 @@ static void iavf_print_link_message(struct iavf_adapter *adapter) speed = kasprintf(GFP_KERNEL, "%d Mbps", link_speed_mbps); } + if (!speed) + return; netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed); kfree(speed); }