Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6955756rwb; Tue, 22 Nov 2022 23:18:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6HUk8BZo2LmSGAazJRQvAJ7BmoZsm7B4gAz631d/xHg2yTKy+9y/a1Nv+P0gFH3T4lHNk0 X-Received: by 2002:a63:5263:0:b0:439:8dd3:c3c2 with SMTP id s35-20020a635263000000b004398dd3c3c2mr6163435pgl.481.1669187929276; Tue, 22 Nov 2022 23:18:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669187929; cv=none; d=google.com; s=arc-20160816; b=KEzdKC2i9hSWmFJFnMuofmZwvtqRwZeTpu3MeZQADK9NmPe4ktIe+QAS1lSArm3Q+Q 9okstDFqzqSmV62z3NGmOOLS4o+kfFr5EpFfobDfB5rHTG5qW2yUHGakg2XeclAOb/lV R/47h3YFCNOz0ZFQF+hWmfPiJevHhym473CmQTxWVC9DoudtsOgUOGyy+0MDTge5fwQM KX3qeaTaeg6dn/TDTHXwz00Bvx+B5t4i0N46Y4Ml9g4ahBl59YPixDwMeRzokjM/SNWL Cg15qt8Up1rLQBQAVznladUyT8TKUbfDwRNudc4V7YtuSTFRVLypCyyrZbLbtz6PwMR7 0kVA== 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=GlMjLqGimc1N3RQwUmvIQGieRUmGO28E8jATdfjyRoU=; b=GNgFjb5qwfR8MqDTpdm75dvdbaQPUNZzSd9YJXeeHkLG2kLBFKW3gsvNudsYZnqf6D +9v4RDUOAz1vSgHfk/buLaXgYvz83JipiRD6a7nlpZkxgLrVt8umPy/AU7e3sVrwkIJz GL2cPCWVdZgarTfNc/pUWLb7x/yA2tUHJiKOl0eSoofBhWq4LdB2II6u2f6OTS7k+K40 Z4WlDRnZiCEiDOFVJVWOb2AOTEKlDhkRDF/pcYugij2NjSTP1VU4dmL1EPz6PRCBGf25 eC8jkidWkGoRD6KWdzPp//2/7EFGaZ8uD0/E3TnlKpfUQ/AZ1YACfRaytjyKW+tbtAN6 6jYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HGluntDq; 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 ls10-20020a17090b350a00b0020d4dc7fa97si1280963pjb.110.2022.11.22.23.18.36; Tue, 22 Nov 2022 23:18:49 -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=HGluntDq; 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 S236117AbiKWGl2 (ORCPT + 89 others); Wed, 23 Nov 2022 01:41:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236114AbiKWGlS (ORCPT ); Wed, 23 Nov 2022 01:41:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA6CDF6099; Tue, 22 Nov 2022 22:41:07 -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 ams.source.kernel.org (Postfix) with ESMTPS id 0C4FDB81ECB; Wed, 23 Nov 2022 06:41:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF754C433D6; Wed, 23 Nov 2022 06:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669185664; bh=BqF+fMKmQdlgBmpTypjbrHnI9gIDVaSpZN4o3tTBEtI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HGluntDqwOHuKBVKwnocM18xZ5/GHfwov2XKMBY6dMhb/gq7Cgm5bsj4kfoA8VZvk u79YMc8/VQLS81gIsUc6qNnCQavEmjIVc3yWZd4C1abPzZ6QGpTmly5evPvnXCJiCj jM1HYdDTMY7aQ2egWzYYlukc8pA0fjHntlYzfVZSfMkP+Vj7BhCsYE9//faaA3FGYp ocMtnANd1XrCDF26gMYSRfNhD6fL1a8dn3bJ+hX7AZDJOzmc4c6ABV1iR22/GJ1hdl T/lPTSAgKy+25GG08yQxLGrVJ8Rc+uLJUONXi/yOF8nEzQeqJgIcaixg2Z70d9LQsz J2ms+4nC+LnHQ== Date: Wed, 23 Nov 2022 08:40:57 +0200 From: Leon Romanovsky To: Jakub Kicinski Cc: Peter Kosyh , Tariq Toukan , "David S. Miller" , Eric Dumazet , 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> <20221122121223.265d6d97@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221122121223.265d6d97@kernel.org> 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 12:12:23PM -0800, Jakub Kicinski wrote: > On Tue, 22 Nov 2022 16:48:15 +0200 Leon Romanovsky wrote: > > 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. > > I'm guessing the code is correct because port can't be a high value? Yes, port value is provided as input to mlx4_init_port_info() and it is capped by MLX4_MAX_PORTS, which is 2. > Otherwise, if I'm counting right, large enough port representation > (e.g. 99999999) could overflow the string. If that's the case - how > would they "fix the tool" to know the port is always a single digit? I may admit that I don't know how hard or easy to implement it, but it will be great if tool would be able to understand that dev->caps.num_ports are not really dynamic values, but constant ones. However, I don't mind if we merge it. Thanks, Reviewed-by: Leon Romanovsky