Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1616462lqa; Mon, 29 Apr 2024 13:50:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9oq3nOn6r+3fl0jPns+BpJZgWtlxdhSPI5Ufr4OkkLdAWo0Ufitkf8yHevLCbgkPMuWZTlEOI8qeAZi293H5UL/UQcf3lpGbFpP4z7g== X-Google-Smtp-Source: AGHT+IGXBlrgw9UK3M76eIdrIwdtMAIWC8y+JJ041ulAmbCQ/qUZlXfR4PJKfewqq4GYZbZagmPH X-Received: by 2002:a17:906:2543:b0:a55:be99:60d5 with SMTP id j3-20020a170906254300b00a55be9960d5mr7906927ejb.23.1714423844045; Mon, 29 Apr 2024 13:50:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714423844; cv=pass; d=google.com; s=arc-20160816; b=ZCB/iZQ4dvvYo6+n0EYnjq6Brmj7n5+7iDWl1aMb8pBnxGrgJJckTYl6j3i+znRHmW drLV5WUqKLMCbZtjBzryO+ZglSjSer0oB6nhnq1RPUKkB3IkfPikwU537EyhOqMke66g Nnjm2NLqmzOyILDI6nhqjIbLIqilV1jF5Qgg6cl9ph92hlk50JCSTN07k/YTRmnCxscd /L4CvIDle5ksxd4uJ9ALfXd1faf5P189Beys2w61zib8oorIoLah3yE4EQIwdrfOsj+j C7/8+CuaaYHJv3dM66MaaEDjj4cI5eHZtUqw20fMtodJkBNx2XkHYUMlNuUzKyQcZM6P OPLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=p+KWfUI7WWjJz2aEzllZVt1Sw+QNmzAz/2DNTRseciU=; fh=82kJQ98y5UgXrYsn7qpaY0KD3ZPPZQJsBwC7jxiieVo=; b=hhBFhBZHZY90IrwxGZTeBvocEFxONYiZ2uzBqDB2uDEWaLh+Gq4VXAp1nP9Bg+U5Ha L9pvXbBqE2Ujj3NrmC7f95BaKXraycjHWjFNmMhibJxeJNmfltPWagTbCdxuVbk712xc lb7FR4AaEvQr05ujS10Wl6PqYOIdXjjvaOUENtEcGrpXm1cNp24qIAuvtgcaqNyIh7Ea utpqyzplybTM+kKe6q5+Wpos5urzbUvDdrdCMtru+XOcAypBpztJq4ORU1EsdzNEFUyd GLNpV0yKzh3YA9eDk+V3r+nGgT9sFy9kYXytHCEcq2T/VysC8rmwW5qgbmqR7Kq+3HIu jn/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iQlsfeP3; arc=pass (i=1 spf=pass spfdomain=flex--justinstitt.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-163027-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163027-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r9-20020a170906280900b00a5193401ffdsi14498287ejc.697.2024.04.29.13.50.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 13:50:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163027-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iQlsfeP3; arc=pass (i=1 spf=pass spfdomain=flex--justinstitt.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-163027-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163027-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id C29F51F22702 for ; Mon, 29 Apr 2024 20:50:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C094178CC8; Mon, 29 Apr 2024 20:50:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iQlsfeP3" Received: from mail-il1-f202.google.com (mail-il1-f202.google.com [209.85.166.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFA3412880A for ; Mon, 29 Apr 2024 20:50:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714423836; cv=none; b=DRSx0264eWh3Det0Xd2O0itr9jA4rVqzsR04r5M206+HNHwgW3yLh1BqxlPKTgKiVZG5v+81PUYT6VPCai0h7NzARt0AOXd7u5rTamttUobrUEIQBC9xofH6UcMXBNVwKkWpnbpRsbRTqzkkjvZveL1dJmLZLck11DMJoJSgF1w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714423836; c=relaxed/simple; bh=E51RN5MCBslyxtFShtUwThE7vElft68Pwp0ik5uTa94=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=kZabgkdwQYXkw554Lvr4odUmuNphhFDCLYW3E3prNvX1y0nw2V7XSn0cY7wFu2ozRiBe//Lapyff4rrTxnKC751gaABFsGOH3bIChwENYhwfyzplMooZAXTo/MGdeESAmKOCvhKRbhR4Mee69L6qCOlZvfgLHlEdx6GpUJ5Y9qU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iQlsfeP3; arc=none smtp.client-ip=209.85.166.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com Received: by mail-il1-f202.google.com with SMTP id e9e14a558f8ab-36b3b387b4eso58862615ab.2 for ; Mon, 29 Apr 2024 13:50:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714423833; x=1715028633; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=p+KWfUI7WWjJz2aEzllZVt1Sw+QNmzAz/2DNTRseciU=; b=iQlsfeP3PNVldcJa9zzyk5dcdlNcSO4Hs6D8TTNB2xJ2WCMdN/zxTziC/KLYbw/0AC vs7ddWBnIMzgwG9JKcXCibZLcjD+KeeF9e3V9MVkW/B94ARTVhELXNsUHSlN/LW68vvY qf/Mfrshqq/heqZ3ZLXSvWMnvjoi6U3Vv7wsU6cWgwBHf7MZze+qA9r396FOiuXRj1sL 2F3S/qqPvmPk7VYncU0baxJoOnFS4i9B2/VRdORqZ2AjZgJUG9+HNQVVyVmQDWUtpqN1 6uG3iZ6VwVKDhT87CyuuPGxceZiZKd6+kDKLHgAj1MxZ7iFfJcH5CG+dstD/gy4kp7lv LNyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714423833; x=1715028633; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=p+KWfUI7WWjJz2aEzllZVt1Sw+QNmzAz/2DNTRseciU=; b=IVbb8LeEKdyaVnUWZ+jzQ341gXn2F4Lt2mg4XIzP8h0wM/36DcRNzrFcMb0ug+TUzV s4cFAMaoCQy5VSOXgGRYO/drKxW4bh2xemyeYRTyT3BYkwyoDoP+Pcg7NCkhIgXiOoX9 NEAfJax0n+XFoiLp7fyVA4hOGcXgrbZUlNEM6ptQiS9JJO76vsrbcBlP3NtwZs3B8YKU 05vMIzsjqolMZsNgN+Rc4S68giFG19KUzcy1iAWgOb73fkSkDX3Q5qhPuZcZVIN2VQvk FiY3k6NVKbL4/ZC46U9m5EMDuCubde6VAWwO2u4snOppzilxr+HBXlZagVqkAnrZLHFA 6RRw== X-Forwarded-Encrypted: i=1; AJvYcCXsZSex5xDxI6RQbi9kPOhv0MVLH7lhZUl7JhJWtLweT0pVAxQf7U8+36wNOh+VKWAleXBULcy8raJgu8yrHAwj+96F0iH0BveLm2lk X-Gm-Message-State: AOJu0YwVjwfrMSgytXYcrqZbWwuCe0B/MlT9wbJHDr4v5dzyqB3NDzH7 BCHCREtRokEiiNExpwxO4zQhZKpbhi5ZpgKAXOlN31cxBKyQ5Pv/vNmr857GY92BzA/TX8fA3Sg X4+YliWJ2Ycwqv+mQd30jLA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6e02:f13:b0:36c:4405:68af with SMTP id x19-20020a056e020f1300b0036c440568afmr265464ilj.6.1714423832942; Mon, 29 Apr 2024 13:50:32 -0700 (PDT) Date: Mon, 29 Apr 2024 20:50:30 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIABUIMGYC/x3Nyw6CMBBG4Vchs2YSqJXbqxAXWH9lIinNtFEI4 d1tXH6bcw6KUEGkoThI8ZEoq8+oy4LcPPkXWB7ZZCpjK1sbjkm9Czu/oR4Lh/UL5VnumVMCO27 bvrs2fWPtxVHOBMVTtv9ivJ3nD+WqHI9yAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1714423831; l=1762; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=E51RN5MCBslyxtFShtUwThE7vElft68Pwp0ik5uTa94=; b=KRsbfMxM48ZQuhpUdtIv3IR8y1K3aT/WjQXifMOc/OUMsw4zO+bfvDG1CgeQ8ial9UKusJEFS EIocTm4zPwKBfi9QfaKdU3X/YObu5KAKXEKmxSx6ktLmw/kSeaBYng3 X-Mailer: b4 0.12.3 Message-ID: <20240429-strncpy-kernel-power-hibernate-c-v1-1-8688f492d3e6@google.com> Subject: [PATCH] PM: hibernate: replace deprecated strncpy with strscpy From: Justin Stitt To: "Rafael J. Wysocki" , Len Brown , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" 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", resume_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#strncpy-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 --- Note: build-tested only. Found with: $ rg "strncpy\(" --- kernel/power/hibernate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 43b1a82e800c..0a213f69a9e4 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -1361,7 +1361,7 @@ static int __init resume_setup(char *str) if (noresume) return 1; - strncpy(resume_file, str, 255); + strscpy(resume_file, str); return 1; } --- base-commit: d7ad0581567927c433918bb5f06f3d29f89807d3 change-id: 20240412-strncpy-kernel-power-hibernate-c-77985696443c Best regards, -- Justin Stitt