Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp88716rdh; Sat, 23 Sep 2023 02:43:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGn4WmnlSzR4zeek3NuIBs8I2ceT/yI3hV64qvYXkGY7ucjBZ8tnUXOwdHUTqxbt2pzKBYw X-Received: by 2002:a17:902:ec82:b0:1c1:f5a6:bdfa with SMTP id x2-20020a170902ec8200b001c1f5a6bdfamr1659809plg.7.1695462221034; Sat, 23 Sep 2023 02:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695462221; cv=none; d=google.com; s=arc-20160816; b=vIVy5TxfMPDXQOF+nyEucXhE/Bn4RxSnnjWdpxVOHu/VloINlFV05RWxN4xFqTp6OE +cZB0P9rEalskjcY6miNnwMEsKmu9Xm1JBsyO2ni0T9UCcShScOlTwc1OE75OI6FmQ+4 8lyDpjFRVzXTzj6zJk9feeQqNP/lMx47bfBzEnxhAxyHJ+Hl/zNw7hjemMmI1fL10Wgu uhdP6DYOOPxHWLNp6jFm9QdANp6aSM4G0jntX7ui2YbRc7+pFUQJKOLbVpex9U21l479 OYEVFUjl3lE9cMC85sijhUFmEFyScfkKS6QON1CmoddvlwCO9HMAE8iGQwtrQyO1cqJT U8Lg== 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=X+CtKcB78+yvu8ZZawbK0NDtaqDQpwnaiaMKGnIwB/U=; fh=PkiRXV14B9rRQqKg0a4dV/1ASisWumtBs2+2PcHXshs=; b=GAp89XejmBhBlTTzzJsWTfcpp1NAXK4TOOCsDinoLA0/jPaTQiXlohm7w4tJ3K7U0F V4+P6fhhsXrWWrX2rzBjDgmElHcxH3l4h6cOfEPilXUp6+Mbixu6hjd9BfF5nz/vEJ2L CCM1V0gEsjyzlrM3KkG1QLg4h/DjHIvbvPh7aH09XRSXYl6wR4OR+9u5aZ4fy/BDPjWb 2zjItFhTndKe71e6J0mMU14Gp3KbD+ht1n05Y+jagGjad9CCSRW1A1+5wa+K7slb0Igx cFxndOR0ZC55IEeazkEIuWqNbxqFdBefxGYA6iTkQak02pcWL0Smbs7AsJETiW3om/ad x6eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=C2HhcJ+R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h14-20020a170902680e00b001bbc138af04si5360773plk.158.2023.09.23.02.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 02:43:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=C2HhcJ+R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 163C881D6D94; Fri, 22 Sep 2023 22:56:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbjIWF4N (ORCPT + 99 others); Sat, 23 Sep 2023 01:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbjIWF4J (ORCPT ); Sat, 23 Sep 2023 01:56:09 -0400 Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E77721A1 for ; Fri, 22 Sep 2023 22:56:00 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id jvcTqd9qqGc65jvcTqO2V0; Sat, 23 Sep 2023 07:55:58 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1695448558; bh=X+CtKcB78+yvu8ZZawbK0NDtaqDQpwnaiaMKGnIwB/U=; h=From:To:Cc:Subject:Date; b=C2HhcJ+R6sDDIHtYI2gXorhU6B3gVMn9SuoGR3X5rIh+wNYt/hPC9jn5cSqBv6Za3 vIomc5Wzz6nbuyiGZj1/xfCA09+GMJvzSEacyyi4ya7gK1yfbkboYwJpsZr8xqnOLR qHbgNE74BI6omSY5SVeN1nk35LHdKEAlWR/SpSG33ivD5XAl/zVNuZVPGvjc53bkRE Vtem4eY3t6/oM+zcOhWmlBIlU2YuxQ7pv0ThCUbyldHA+NpmB/xW/iCd8P5wzG/2sB 2ObQl0jD+Vs83a5Fz1BODZbAEGG3nKOxe5Yr+EK2+oJpUz6Gbv2CHQNVOtNBB38YTZ uXdZxlta2XWKA== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 23 Sep 2023 07:55:58 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Yishai Hadas , Jason Gunthorpe , Leon Romanovsky , Jack Morgenstein , Roland Dreier Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-rdma@vger.kernel.org Subject: [PATCH] IB/mlx4: Fix the size of a buffer in add_port_entries() Date: Sat, 23 Sep 2023 07:55:56 +0200 Message-Id: <0bb1443eb47308bc9be30232cc23004c4d4cf43e.1695448530.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 22 Sep 2023 22:56:13 -0700 (PDT) X-Spam-Level: ** In order to be sure that 'buff' is never truncated, its size should be 12, not 11. When building with W=1, this fixes the following warnings: drivers/infiniband/hw/mlx4/sysfs.c: In function ‘add_port_entries’: drivers/infiniband/hw/mlx4/sysfs.c:268:34: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=] 268 | sprintf(buff, "%d", i); | ^ drivers/infiniband/hw/mlx4/sysfs.c:268:17: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 11 268 | sprintf(buff, "%d", i); | ^~~~~~~~~~~~~~~~~~~~~~ drivers/infiniband/hw/mlx4/sysfs.c:286:34: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=] 286 | sprintf(buff, "%d", i); | ^ drivers/infiniband/hw/mlx4/sysfs.c:286:17: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 11 286 | sprintf(buff, "%d", i); | ^~~~~~~~~~~~~~~~~~~~~~ Fixes: c1e7e466120b ("IB/mlx4: Add iov directory in sysfs under the ib device") Signed-off-by: Christophe JAILLET --- We could also use snprintf(), but it would just lead to a bigger patch for no additional benefit. This patch is already certainly more a clean-up than a fix. --- drivers/infiniband/hw/mlx4/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx4/sysfs.c b/drivers/infiniband/hw/mlx4/sysfs.c index 24ee79aa2122..88f534cf690e 100644 --- a/drivers/infiniband/hw/mlx4/sysfs.c +++ b/drivers/infiniband/hw/mlx4/sysfs.c @@ -223,7 +223,7 @@ void del_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num, static int add_port_entries(struct mlx4_ib_dev *device, int port_num) { int i; - char buff[11]; + char buff[12]; struct mlx4_ib_iov_port *port = NULL; int ret = 0 ; struct ib_port_attr attr; -- 2.34.1