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 18E4329425; Mon, 16 Oct 2023 19:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FX6MQtvL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B660BC433C8; Mon, 16 Oct 2023 19:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697486321; bh=QJt2FjmAOk4+5+b+Cj8Y/yCy8j4cnH5smrJ3zqV3En4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FX6MQtvL92gviz8tSxWSfFL5w4oPc6M/5NeJ4RfP2w0ZjzCQNmfkcliOrohxxdXRu mGf7jkY+Qp5+gnHnuKwnfGIOb/LYqvb7lLStTNsS5gmREJuEkVMPP5zE9qKJqsXX+h fjP+2hFDYTIHs2Fkw5mxJ65yjcMcMJbItI+s02EDjyW8kghqpS03VNdQ5OMrWCydCP DmUI2rWd5/7TberVoCzCL9sZYaaHCgCWWyq/OrrxP/rjg3kR5kWZSdhIeH2na82psT jkfMsfUdXTGz7eb7AIk0Aj2tV/3myWkuU/HPgTAkuVs5YQVN0or+J4/5Jzjq50e9bI O5EYsKIjUxeyw== Date: Mon, 16 Oct 2023 21:58:36 +0200 From: Simon Horman To: Kees Cook Cc: Justin Stitt , Thomas Sailer , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-hams@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] hamradio: replace deprecated strncpy with strscpy_pad Message-ID: <20231016195836.GB1751252@kernel.org> References: <20231016-strncpy-drivers-net-hamradio-baycom_epp-c-v2-1-39f72a72de30@google.com> <202310161242.B0F9B693@keescook> 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-Disposition: inline In-Reply-To: <202310161242.B0F9B693@keescook> On Mon, Oct 16, 2023 at 12:42:22PM -0700, Kees Cook wrote: > On Mon, Oct 16, 2023 at 06:42:42PM +0000, Justin Stitt wrote: > > strncpy() is deprecated for use on NUL-terminated destination strings > > [1] and as such we should prefer more robust and less ambiguous string > > interfaces. > > > > We expect both hi.data.modename and hi.data.drivername to be > > NUL-terminated based on its usage with sprintf: > > | sprintf(hi.data.modename, "%sclk,%smodem,fclk=%d,bps=%d%s", > > | bc->cfg.intclk ? "int" : "ext", > > | bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, > > | bc->cfg.loopback ? ",loopback" : ""); > > > > Note that this data is copied out to userspace with: > > | if (copy_to_user(data, &hi, sizeof(hi))) > > ... however, the data was also copied FROM the user here: > > | if (copy_from_user(&hi, data, sizeof(hi))) > > > > Considering the above, a suitable replacement is strscpy_pad() as it > > guarantees NUL-termination on the destination buffer while also > > NUL-padding (which is good+wanted behavior when copying data to > > userspace). > > > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > > Link: https://github.com/KSPP/linux/issues/90 > > Cc: linux-hardening@vger.kernel.org > > Signed-off-by: Justin Stitt > > Thanks! > > Reviewed-by: Kees Cook Likewise, thanks. I prefer this over v1. Reviewed-by: Simon Horman