From patchwork Tue Aug 22 23:59:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13361531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08B0DEE49A5 for ; Tue, 22 Aug 2023 23:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231833AbjHVX73 (ORCPT ); Tue, 22 Aug 2023 19:59:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbjHVX72 (ORCPT ); Tue, 22 Aug 2023 19:59:28 -0400 Received: from mail-ot1-x34a.google.com (mail-ot1-x34a.google.com [IPv6:2607:f8b0:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41C6ECF9 for ; Tue, 22 Aug 2023 16:59:27 -0700 (PDT) Received: by mail-ot1-x34a.google.com with SMTP id 46e09a7af769-6bc807e99adso5420245a34.2 for ; Tue, 22 Aug 2023 16:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692748766; x=1693353566; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=cGRueg2eqYbMCY2ShRbCc3/RucSV6L/B/eSOD25AmaY=; b=oE7rm9AjFtO/wJhPR4I/B3C9PzPl0U9GIJtJ8lqhBf1+Myf/+D2iSRfZgrmLr7mR/x nMayejh5oe5AWTapQPCLq5jq9CY0Pyc9ctwVerkEBlIECHUhVK4vkKvWYwR27pziznqm 9W/6Luzdj+ygswvRfmFxADqiAuYOViFaMm49y1CXqPV3sBb/+KuycOsoULepp7onHymj YJMqT/JW19FcVl0zqu0VHtUAcLgBtMlKbMHcBgSSsL0o1dCaBKqqRdrNmCLdDIilXVF7 j8JurhCuRPmIhc+12Fomrtw8IDBZ0+NlB1WaYQiZQ5AwOcourf0LmrvpQCxGkEeWzW/q LmPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692748766; x=1693353566; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cGRueg2eqYbMCY2ShRbCc3/RucSV6L/B/eSOD25AmaY=; b=GTXD++YOhvld94aynZzdBhOIwJWqkMcNH4JLdgDIQpz0gvV9BoTXFA/9r4k/M9GQ5c y0/6CBqkz0CBrCaTHR7rRs1/aN99KqXx3CZWJ+pcW//b7lUzcRRm1v4Wy7cvo15qQq0V 55IjECBPivI6Hpc5C9fA23ImoHUZEvqoNzrcL1rCTslZlzNqdDqi3mmQeOxZaI7L7YUj OGyCNY3wVgZqo66m3FHMFhn9DoTtpgfYM1IGU/ZsK1rutXSz70kEo4+iL5DQQsdbWXD9 TP10ejGIs1wI19xdAxVJTd1wPotlDX2X5UnlWoGp6TSiQN3z68qjn5HF4KTHuFIIbbGJ TL7g== X-Gm-Message-State: AOJu0YyMnJmE0LAawfMfN7rorDGTpwLkXPeImcU+M1UmQOiEslzRtnmu 6A/F4dWx//5ubTq53NuQv8wTbMeuSjVy3h4Z4g== X-Google-Smtp-Source: AGHT+IEg7NbVScd59jOYBOeVb3GuBkFoZlJ1jMAeIVZP8P7/g2W+bAHAovNBatxzdjVp9Qhlv5I+h6M7X52P9QgtDQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6870:c796:b0:1bb:91fa:7aab with SMTP id dy22-20020a056870c79600b001bb91fa7aabmr174453oab.1.1692748766615; Tue, 22 Aug 2023 16:59:26 -0700 (PDT) Date: Tue, 22 Aug 2023 23:59:26 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAN1L5WQC/x2N0QrCMAxFf2Xk2UCtjIm/Ij60WabBrStJGcrYv xt8PHDPPTsYq7DBrdtBeROTtTicTx3QK5Uno4zOEEO8hGuMaE0L1S/meaU31qRNmjuGtIyzFN/ nBYepz0SpDwMn8KuqPMnnn7k/juMHT0R0HHYAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1692748765; l=1601; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=DvMuu8/lxku646YrnJJTNn2dZrYri5zBU+GthJXHRdo=; b=y9qu1DfwgWfym6uoXSaFbpI+RHlMMNIUgnNRgLwXSTUj4rO+8MpulMdSPc9QurH/sB/n7zscE V8PMAm229yiAOd/7pdZGUlXbYKP5Dt7IqsFe36jFT6eAtvHiQDn1fkp X-Mailer: b4 0.12.3 Message-ID: <20230822-strncpy-block-partitions-cmdline-ibm-v1-1-154dea8f755c@google.com> Subject: [PATCH] partitions/ibm: refactor deprecated strncpy From: Justin Stitt To: Stefan Haberland , Jan Hoeppner , Jens Axboe Cc: linux-s390@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org `strncpy` is deprecated for use on NUL-terminated destination strings [1]. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on its destination buffer argument which is _not_ the case for `strncpy`! Link: 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 --- block/partitions/ibm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- base-commit: 706a741595047797872e669b3101429ab8d378ef change-id: 20230822-strncpy-block-partitions-cmdline-ibm-7f5bcca507ea Best regards, -- Justin Stitt diff --git a/block/partitions/ibm.c b/block/partitions/ibm.c index 403756dbd50d..e5893cf71b57 100644 --- a/block/partitions/ibm.c +++ b/block/partitions/ibm.c @@ -111,11 +111,11 @@ static int find_label(struct parsed_partitions *state, !strcmp(temp, "LNX1") || !strcmp(temp, "CMS1")) { if (!strcmp(temp, "VOL1")) { - strncpy(type, label->vol.vollbl, 4); - strncpy(name, label->vol.volid, 6); + strscpy(type, label->vol.vollbl, 4); + strscpy(name, label->vol.volid, 6); } else { - strncpy(type, label->lnx.vollbl, 4); - strncpy(name, label->lnx.volid, 6); + strscpy(type, label->lnx.vollbl, 4); + strscpy(name, label->lnx.volid, 6); } EBCASC(type, 4); EBCASC(name, 6);