From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E7FC8F70 for ; Tue, 14 Nov 2023 04:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Id+2PNl+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1940FC433C7; Tue, 14 Nov 2023 04:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699934944; bh=KEzu8CMPHLdHv9I7MdibYZjeRPhS5mvEErnmSoIuKJw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Id+2PNl+tT1IdBMVKMvcyK63kgBWz0H1jqDw75nhE2q+NG9B697d0uazKOJx+1qOv GxJZQ9tmrpOvjTgW1pw5QoKhGlcgUkEjSUA5DMJMZHovjAHGhDZlGWg3mbiZZ+kvnj dPqJC8+AuDDzilej/0W8RvyCFsb1dPIuA/0OI/TJvoWGWeCRYtBPruXH0NJ7+ZlBB3 X9YlfENc3fsl0/SrqCmnTVCxMKh6FA3VypiaYp5k6M4eG++j22aEQ7G3yzvEjXJ4XF EtRF603ufMmqHNFvNYi4ecQCEsRDFoXzy/WD/mTmaEifa/i9ELWyunbILwHODCa6YP VLCRAu0ZmXMzQ== Date: Mon, 13 Nov 2023 23:09:02 -0500 From: Jakub Kicinski To: Gal Pressman Cc: "David S. Miller" , , Vlad Buslov Subject: Re: [PATCH net] net: Fix undefined behavior in netdev name allocation Message-ID: <20231113230902.7f342501@kernel.org> In-Reply-To: <20231113083544.1685919-1-gal@nvidia.com> References: <20231113083544.1685919-1-gal@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 13 Nov 2023 10:35:44 +0200 Gal Pressman wrote: > Cited commit removed the strscpy() call and kept the snprintf() only. > > When allocating a netdev, 'res' and 'name' pointers are equal, but > according to POSIX, if copying takes place between objects that overlap > as a result of a call to sprintf() or snprintf(), the results are > undefined. > > Add back the strscpy() and use 'buf' as an intermediate buffer. It may be worth mentioning that it is fairly common to put the format in dev->name before device is registered, IOW this condition takes place a lot? IIUC once we cross into 3-digit IDs we may crash? With that and the right fixes tag: Reviewed-by: Jakub Kicinski Thanks! -- pw-bot: cr