Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1937211lqa; Tue, 30 Apr 2024 04:03:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWtp9mpnFl6Ks4axuWnF26DU4gh+4nWypsfNAPKTgTNX6K7QeCE5h5GXmSOXdS1GoUmw7bps+VW0d0zcYTxKfaI6T+LU3quowRVlrapIQ== X-Google-Smtp-Source: AGHT+IHV0yr+n06nZi3DDeB3yqTcvQRio3ZVZ5s1aLldomSgNtm3rJa45/LZFdpop0bm+H+HPREm X-Received: by 2002:a05:6a00:1906:b0:6ea:e2d8:468 with SMTP id y6-20020a056a00190600b006eae2d80468mr17788409pfi.26.1714474989880; Tue, 30 Apr 2024 04:03:09 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p35-20020a056a000a2300b006ecff4030f9si21936944pfh.326.2024.04.30.04.03.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 04:03:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=GGyug1LK; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-163814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6FAD5B20E03 for ; Tue, 30 Apr 2024 11:01:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 373FD12C487; Tue, 30 Apr 2024 11:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GGyug1LK" 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 57BF712C462; Tue, 30 Apr 2024 11:01:29 +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=1714474889; cv=none; b=Sm1A0K646qvMSz7KQHerrFX3xwpZdi9f4ZNqCjk5m2feQ7ReMPnTbkCVXdQke+suz+z4jI3KbfSQM4clPvjLy50E6saSufBpYXAm6J9xC4xXJVrw5VRWU2zTcLiJppxcK0HtYP1Tw4ru76DdWMX4RUSUwEcOGY1iX/Qi3yPCVQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714474889; c=relaxed/simple; bh=7k26v8spb/SVU8KHpWsFuVmQm5vt6zLCxU8gvvmJook=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=O8dlz9SV9FxXm9X3ylGmlwByoC0VjJlmN1VXHFTu9z/8CdOLNgvPaCnDprlAu7ORyhifHdIzVH8DFIlT1A2I0T4P15ooOnG7Qfzdqhz2TdliRktCOeZB9hT19z+cHRuU5zxCGFMozFWFKuTTCRp/P0xu+8tUQz2x+3xKXYyerc4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GGyug1LK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2052CC4AF1D; Tue, 30 Apr 2024 11:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714474889; bh=7k26v8spb/SVU8KHpWsFuVmQm5vt6zLCxU8gvvmJook=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GGyug1LKuNWymH/ERsE/SqyEKJ4tQDhqpB7AQgHS3JmYwT9W4LmsEmygP+76DlGdo WhGMh2GIqdED2SU1fXEmwwClyPJNOGcfJmBw1uhr9lPaknoR0M35XNdxKCFeYg7wpY UkBXZx05wD7PFKzzgnYIvRFsDDClcgMNeQftm0lG4ljfQNyV+5siClgSYhnIo4N2m+ c5Wnq8Dm91MAAQcXMapRUR+bza06buUeqnC8T2hUri5biPP8f9fzQlfU4lODvbTmpc /C4ffB4pOetheQfpS2tRWARniB2bWz99RWGM0EFCYbNGObpf6zTExRcNAY/vYDeT2x kxTN0xr6+h+Hg== Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5ac970dded6so1319151eaf.0; Tue, 30 Apr 2024 04:01:29 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWk3yHi3Php4wEkSyjV878+3BZIptycLh7VXPwCn1O+FQ7F84OQsoV44hyA0NwAbD3J/vMzFvhMY2WqXkHdYbt9DNvp+VxTBpqB9veRtZvxCgwb/AzZL1DWhRpY2/UkkRVdlNeDsuXqAYz3QmZjwgyec8DXqid19kH7jFNzTQIsdqhqzJdLzPo= X-Gm-Message-State: AOJu0YwCgbDcGa2NJcN8731s0d4RJc8xFPAj/+X9NRchuwobsumLHToX VzQQiSihOXxJ/iPz9FhSUDAWlzgGPq9mHOzTxmlldYVR1ZM2Jky5E6ydG2yDSKSRfJHY1vyMhmv 4KXhKuDYEpJTaqtHhSaJEaYQz2SY= X-Received: by 2002:a4a:a683:0:b0:5aa:3e4f:f01e with SMTP id f3-20020a4aa683000000b005aa3e4ff01emr14418920oom.1.1714474888346; Tue, 30 Apr 2024 04:01:28 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240429-strncpy-kernel-power-hibernate-c-v1-1-8688f492d3e6@google.com> <20240430093625.qbuaxltkrmlaoiza@dhruva> In-Reply-To: <20240430093625.qbuaxltkrmlaoiza@dhruva> From: "Rafael J. Wysocki" Date: Tue, 30 Apr 2024 13:01:17 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] PM: hibernate: replace deprecated strncpy with strscpy To: Dhruva Gole , Justin Stitt Cc: "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Kees Cook Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 30, 2024 at 11:36=E2=80=AFAM Dhruva Gole wrote: > > On Apr 29, 2024 at 20:50:30 +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. > > > > This kernel config option is simply assigned with the resume_file > > buffer. It should be NUL-terminated but not necessarily NUL-padded as > > per its further usage with other string apis: > > | static int __init find_resume_device(void) > > | { > > | if (!strlen(resume_file)) > > | return -ENOENT; > > | > > | pm_pr_dbg("Checking hibernation image partition %s\n", re= sume_file); > > > > Use strscpy [2] as it guarantees NUL-termination on the destination > > buffer. Specifically, use the new 2-argument version of strscpy() > > introduced in Commit e6584c3964f2f ("string: Allow 2-argument > > strscpy()"). > > > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#st= rncpy-on-nul-terminated-strings [1] > > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en= html [2] > > Link: https://github.com/KSPP/linux/issues/90 > > Cc: linux-hardening@vger.kernel.org > > Signed-off-by: Justin Stitt > > --- > [...] > > Reviewed-by: Dhruva Gole Applied as 6.10 material, thanks!