From patchwork Sat Oct 21 18:03:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 156484 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp420368vqx; Sat, 21 Oct 2023 11:04:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnZ+jHidl7Ao3RJSWc+tX4ypkEYeQzF3vtslGj7N48kJW//T47noGlEnc2N+YtRd00AFR7 X-Received: by 2002:a05:6a00:1e06:b0:68f:c8b4:1a2b with SMTP id gx6-20020a056a001e0600b0068fc8b41a2bmr11961976pfb.17.1697911482994; Sat, 21 Oct 2023 11:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697911482; cv=none; d=google.com; s=arc-20160816; b=qXRhRM2xunz/4WdDQ0ebNB2nMrpIKd9A0DUYPhLnD8CWVMqnL2SS6NUnWhs82BpHit IVlfJUw9ASlbRBONrC1dnhydl0VWt3ay6zSXPa6ClZ4fjUOvgP0iSsD2rSqSpecetYfw dbR7Df4G+A9ZuqMpawLS6RZWVmSA42fID4xwOfMK9+t+xW/r/uFvakq8RH74nkl2my68 keWfEFzPYebxtIkjWxWpGY9Inhvlb5vo9+Esbly286ZjPwsfG5dDkTpV4JMecofQiumi 0X+/MB692eMej+MSJQN3JgJTueEeJELA+uTnKBOxo28UdS70hbSA7VBNxO3pDaeMjRu6 J9vg== 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:dkim-signature; bh=WGG4h3fjFFGpf7YbjWTDEm1O70pn20++HFr6LfKdydw=; fh=V1VFEYEf5LCHZkbttuKs/YSrH6f3Ccpwbq2xEnKc3Vo=; b=xvdJZD5J01BMoyTbX5b34ojoSk+INB5bpg/ORW+cuaAcWeQ6BrcNujR4OPLKknlEMU D/XdRo00dbMa4NOD4qeoRX05WdUTIvPJD7CKgRtxOe+VLmZZ4KnDayzbQGzEzQeJOEJM fNS6NK4hrcbuwI6yp2XwuwDDlyCiw3mOrvbo7oVR9Rz8ZxOkqJUAox81Cg3w+y4/VygM 0D+m0H0RuGhIVlWAz6d3dDYkAsMxfFhaVQy8C9kAy+FoyQQY2d8CmXaoUh6yLaI8JZnp vwAKPQlPJeKmSEgkjMHxocPwpwomqHBMs9wsDBgjoI6FKv7oNfvUgV06HGC1TqxBxnwZ OibQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="az72N/+V"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id r27-20020a638f5b000000b00565f5281804si3939075pgn.195.2023.10.21.11.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 11:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="az72N/+V"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 60507804C20E; Sat, 21 Oct 2023 11:04:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230271AbjJUSEF (ORCPT + 26 others); Sat, 21 Oct 2023 14:04:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232012AbjJUSED (ORCPT ); Sat, 21 Oct 2023 14:04:03 -0400 Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C59E4121 for ; Sat, 21 Oct 2023 11:04:00 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id uGKJqVjkbvhM3uGKKqJsb4; Sat, 21 Oct 2023 20:03:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1697911439; bh=WGG4h3fjFFGpf7YbjWTDEm1O70pn20++HFr6LfKdydw=; h=From:To:Cc:Subject:Date; b=az72N/+VVqLJjQfVTcgZ4ikmpD61YAW5vF1x8FXwB4ztn4zLiyLT8trgH+bnLdIIl Kj1fX7IhGKpLllE/jz9ugHU7aeEtzbsC/qLpem930KKhixLtBl1s+96flijMwKy8hm JGH6RpVsS9NGSv6SANu0DfjDyD6a/riJs5AkiPSvD9UPehB6FBBOm9oNxIIvHtU4WU pvzQDqQYtm0+MqsPrTGPxA06EGnG5nvU3FRIEeRirCWBenTNqxDqwt9sBsicrzJLq6 HKAj/kO4BiNCT2eDRw55nOzwdhFi8R02vudrIFBFn4YBB5MBvT2CMyK2r6L7O10/kP /mw23XndOpY0g== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 21 Oct 2023 20:03:59 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: keescook@chromium.org, Michael Hennerich , Alexander Aring , Stefan Schmidt , Miquel Raynal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Marcel Holtmann Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , Stefan Schmidt , linux-wpan@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net] net: ieee802154: adf7242: Fix some potential buffer overflow in adf7242_stats_show() Date: Sat, 21 Oct 2023 20:03:53 +0200 Message-Id: <7ba06db8987298f082f83a425769fe6fa6715fe7.1697911385.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sat, 21 Oct 2023 11:04:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780389231338675774 X-GMAIL-MSGID: 1780389231338675774 strncat() usage in adf7242_debugfs_init() is wrong. The size given to strncat() is the maximum number of bytes that can be written, excluding the trailing NULL. Here, the size that is passed, DNAME_INLINE_LEN, does not take into account the size of "adf7242-" that is already in the array. In order to fix it, use snprintf() instead. Fixes: 7302b9d90117 ("ieee802154/adf7242: Driver for ADF7242 MAC IEEE802154") Signed-off-by: Christophe JAILLET Acked-by: Michael Hennerich --- drivers/net/ieee802154/adf7242.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ieee802154/adf7242.c b/drivers/net/ieee802154/adf7242.c index a03490ba2e5b..cc7ddc40020f 100644 --- a/drivers/net/ieee802154/adf7242.c +++ b/drivers/net/ieee802154/adf7242.c @@ -1162,9 +1162,10 @@ static int adf7242_stats_show(struct seq_file *file, void *offset) static void adf7242_debugfs_init(struct adf7242_local *lp) { - char debugfs_dir_name[DNAME_INLINE_LEN + 1] = "adf7242-"; + char debugfs_dir_name[DNAME_INLINE_LEN + 1]; - strncat(debugfs_dir_name, dev_name(&lp->spi->dev), DNAME_INLINE_LEN); + snprintf(debugfs_dir_name, sizeof(debugfs_dir_name), + "adf7242-%s", dev_name(&lp->spi->dev)); lp->debugfs_root = debugfs_create_dir(debugfs_dir_name, NULL);