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 2D3F4D51D; Sun, 14 Jul 2024 04:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720930152; cv=none; b=q0yMX0ncXciKK+Y4xxAZ3Vy9n71gmMwEC3J8cO+ed2d9OyoCkz3KcPnYBvXIoSejAzTMFEf1Fly8t4cP3q1AxUdwyK3tVbwh3Vf1VabUHxwPRpTib9QoQ2tQ+BuXSBNvGzDIze8bChHsYMKa0M3pR394voKLLoH7duyoJO/8Izk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720930152; c=relaxed/simple; bh=4RSIRByYvOzyuNRQjFNcr9BxvQQaQC7rVLUDeCW4J7c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hHAL4g0Ea2OcJ4PdRgN1aa8aFLvlfkDOGZZnOh5egqw+nVy4lQ7gPuBAhkmcpSyfL1JeAZ4Q1QX2T4HfoL3uRcm8UH8HKZ5twf0VLX4HHDlUZv9SPFBMxIhZ8rNhKwDk8f6rp5q/G61z2dOUJfW1ER4lxfGNqrhXuaZJh5xbhCU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P9IXmtWu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P9IXmtWu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BA17C116B1; Sun, 14 Jul 2024 04:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720930151; bh=4RSIRByYvOzyuNRQjFNcr9BxvQQaQC7rVLUDeCW4J7c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=P9IXmtWuahNWN2DaXF2GyAYguohByViaJYiTTVBqSCgpAcSstIrHDBOpptA6YzHIz BpKx32v2ABuPrEwL/uUxqNuPkBstHzATuQUVa2qFP2oMkt0aSj0WPluI1y3uAQEyCw KolQ16wOjcOUFg5a+hUzB6cj7tMoAUuBAd8w9cpj/FAguZQ3nOVz5CeJfr/jke64L7 McGxXWZ8YzxxduOuqKJmte9VwBBmUksy1O6WNnf2f0C5F71rBvagBec0OvyYDl8p54 uW4vQvI5SjUNE9ojvQo8UN360awXQfDRJ0SPxZA/KB48K6quUMg5EbydHwYUoL8b8a aRnfasPSlp5aA== Date: Sat, 13 Jul 2024 21:09:10 -0700 From: Kees Cook To: Eric Dumazet Cc: "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] net/ipv4: Replace tcp_ca_get_name_by_key()'s strncpy() with strscpy() Message-ID: <202407132108.1577A694@keescook> References: <20240711171652.work.887-kees@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Jul 11, 2024 at 10:38:01AM -0700, Eric Dumazet wrote: > On Thu, Jul 11, 2024 at 10:16 AM Kees Cook wrote: > > > > Replace the deprecated[1] use of strncpy() in tcp_ca_get_name_by_key(). > > The only caller passes the results to nla_put_string(), so trailing > > padding is not needed. > > > > Since passing "buffer" decays it to a pointer, the size can't be > > trivially determined by the compiler. ca->name is the same length, > > so strscpy() won't fail (when ca->name is NUL-terminated). Include the > > length explicitly instead of using the 2-argument strscpy(). > > > > Link: https://github.com/KSPP/linux/issues/90 [1] > > Signed-off-by: Kees Cook > > --- > > Cc: Eric Dumazet > > Cc: "David S. Miller" > > Cc: David Ahern > > Cc: Jakub Kicinski > > Cc: Paolo Abeni > > Cc: netdev@vger.kernel.org > > --- > > net/ipv4/tcp_cong.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c > > index 28ffcfbeef14..2a303a7cba59 100644 > > --- a/net/ipv4/tcp_cong.c > > +++ b/net/ipv4/tcp_cong.c > > @@ -203,9 +203,10 @@ char *tcp_ca_get_name_by_key(u32 key, char *buffer) > > > > rcu_read_lock(); > > ca = tcp_ca_find_key(key); > > - if (ca) > > - ret = strncpy(buffer, ca->name, > > - TCP_CA_NAME_MAX); > > + if (ca) { > > + strscpy(buffer, ca->name, TCP_CA_NAME_MAX); > > + ret = buffer; > > + } > > rcu_read_unlock(); > > > > Ok, but what about tcp_get_default_congestion_control() ? Whoops. Yes. I'll do that at the same time. v2 coming... -- Kees Cook