Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5960572rwb; Tue, 22 Nov 2022 07:08:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf7CueTw7a0xumOr4z6QqPSTKJuUsdM9uSYmdsHly1ckQi5jE2IWIpnnnhsvrdJbbsAI0qVi X-Received: by 2002:aa7:d558:0:b0:461:eea0:514c with SMTP id u24-20020aa7d558000000b00461eea0514cmr11128598edr.296.1669129685604; Tue, 22 Nov 2022 07:08:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669129685; cv=none; d=google.com; s=arc-20160816; b=yoDE1i9BUUm/GAG0nsETVqsvNU9J46VrGWhUz/ji9ZW3HoUrLG39eNFfFu7mu116bl IO/N7xRg+yGszmUSUfOcomaz/dJguB8WhrKo9gbMer2FSUIPrhfQphu7pHxNjjwQpgo/ I4XoJ+j8sFR8LIzDmWFk2ihVv+fgcRaw20iYnW3hLZsEK0YapV7DzYyL53maALGDuvIb 1gl6qA2/0om0oxrTd0ky4I9hCP8dBd3jSvVliEB0QyRV7gPei3YYEo8tSlVCNbSKkN2o WBiCdBOuyk30ElmOzXGgb3AFReRvNDNpFon+EHzOpggyanAuebxIESiuJEkU1v4SGniy oORA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wjcvKorJOugpvsoTmFYJUbom+bXnP1GWh+Gv7WU+N7Y=; b=rhUsP6IwActjILzRSz1cKJPbELDDnh6npuWsV9+sGlNPhLzolPmvr/PrdVoTXCYj6y 7ILYWIvIaKZbYxbcx8m1Zzn4cRaekFsv/+vbZ9mBG1gs1tXCa9KZnSIVC6ik0/Rm0FUr D7R9ErquO5D3QtfUNujpKTVDJRmDkLmNpplj+HLEBL/lYKXB1zVuKp/A/Bh5RnbYwn8q GzVK3pfff7YmIcmyYT+URtmRDcnQcLh5rgvgf2sZRB+Qc97SSMHCBDnHzwNizmxDu74q 4GT4Au8fZ7QFrPgFYvmImlxYiBJGOioAn8+46D9qG1EwnwX/giVdE3rXynF7IU3vPE6A KAmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d0fdR4iv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p16-20020a05640210d000b0046920e7030csi8368344edu.222.2022.11.22.07.07.42; Tue, 22 Nov 2022 07:08:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d0fdR4iv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233156AbiKVOsX (ORCPT + 90 others); Tue, 22 Nov 2022 09:48:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232665AbiKVOsV (ORCPT ); Tue, 22 Nov 2022 09:48:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A8B62606; Tue, 22 Nov 2022 06:48:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 36B3161733; Tue, 22 Nov 2022 14:48:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E235EC433D6; Tue, 22 Nov 2022 14:48:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669128499; bh=lqCUWdMmeZtamXQEK/uSvDyJ1N+krRb43evlfpRGSZs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=d0fdR4ivk8mJ4v0r1rJsp6WCI3EU7K/tUh595I3GwFieuAQHMyGmgY5LBpa1seKdQ vSrlvi7NAL5KWYM6Ux5Ksb+6/faI94FqMijFBnY5u5cP8qMzVEYUi2nNOdrnFaL4Fc KcowLouD0A+ZQ0+LTp/SEGtTTEum05N1sIk/zGFfcwKZ4Ksk2BmijqRsaCjkIFPoI1 UVaCCQn27h+vkXj0xZgp5RJASAgCoOtamEyEa/g4d0yybXGqEyRPlxrBuiTGekLIRc 6QGKhejqw4g7PZzT07liwrL+xQBNPNEQ6WZ3R7vPhM+Pm0Kss83bnBEqiDWWuIY5/g bT7KVaS8d1CRw== Date: Tue, 22 Nov 2022 16:48:15 +0200 From: Leon Romanovsky To: Peter Kosyh Cc: Tariq Toukan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: Re: [PATCH] mlx4: use snprintf() instead of sprintf() for safety Message-ID: References: <20221122130453.730657-1-pkosyh@yandex.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221122130453.730657-1-pkosyh@yandex.ru> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 22, 2022 at 04:04:53PM +0300, Peter Kosyh wrote: > Use snprintf() to avoid the potential buffer overflow. Although in the > current code this is hardly possible, the safety is unclean. Let's fix the tools instead. The kernel code is correct. Thanks > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Signed-off-by: Peter Kosyh > --- > drivers/net/ethernet/mellanox/mlx4/main.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c > index d3fc86cd3c1d..0616d352451b 100644 > --- a/drivers/net/ethernet/mellanox/mlx4/main.c > +++ b/drivers/net/ethernet/mellanox/mlx4/main.c > @@ -3057,7 +3057,8 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port) > info->base_qpn = mlx4_get_base_qpn(dev, port); > } > > - sprintf(info->dev_name, "mlx4_port%d", port); > + snprintf(info->dev_name, sizeof(info->dev_name), > + "mlx4_port%d", port); > info->port_attr.attr.name = info->dev_name; > if (mlx4_is_mfunc(dev)) { > info->port_attr.attr.mode = 0444; > @@ -3077,7 +3078,8 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port) > return err; > } > > - sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port); > + snprintf(info->dev_mtu_name, sizeof(info->dev_mtu_name), > + "mlx4_port%d_mtu", port); > info->port_mtu_attr.attr.name = info->dev_mtu_name; > if (mlx4_is_mfunc(dev)) { > info->port_mtu_attr.attr.mode = 0444; > -- > 2.38.1 >