Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp577711rdb; Sat, 19 Aug 2023 14:08:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWJcDMIV4b+J4Lood+/EIvnAVT3lvnlZXz/7IlYxEVZie8qL1WVveA159YCNYksKyoOdxO X-Received: by 2002:a17:902:f68f:b0:1b8:aded:524c with SMTP id l15-20020a170902f68f00b001b8aded524cmr3421579plg.1.1692479324775; Sat, 19 Aug 2023 14:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692479324; cv=none; d=google.com; s=arc-20160816; b=A7CAu/44ABEpHNzbIoAGfw18PfDPlLg3UX5PLt2YxBt21zGG04uIcfaWtnIuEqgf0o 8Y6hVmyz1lSkGusdE+KZMfqa19QcEDule9aDkd2ZFSgfUB8TnggNvPqRAeFFPRG7gYA3 EisyrJQ3TLDHWJifFQULMTNpvsmJ2jF8msGEOsrvAU5hX2CIzxDIM+wF58q1n1ZmvMkw EjEvlJTu61Jq2gIo0wvwgv/s8ZFJXs/9eFQnMvlxAvmhX/aMTe7nlLs2m668YCC1kRf/ MaZbYBMOiOsT0s2Z0l9ZP/FWZCESj+o0znQjASEowV+4qgUZ3NyE+/qLGmNV4kDEw0b1 3jdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=dgfv9XpiXMzsq2kLywbyVX/AZp8i35sYGiNA5Uju+Tg=; fh=dtv1gAsCGihr2UaqP6qL1gTOtSRIDOQqr2PzOwVkMtU=; b=U6TYjTX7JN4n6XDyBp+wwvkm39V8UsTcGy5oFh7eyb8EjyKV2VXRaNRU2GJlrCJ6F0 ch9xYPP+knGGeyv7h4KW34r1e/gWtE7sS8o+bezSQAC82U0R6cksy9b/KXo979tBDygO gtWFLUGXhFWXgDcNmxrBCjzb5WxFDFEbxSiC6S/Op+IgLO+qNVJG7dU26t2XnRyQRaZq d+6wO7EHeUD/Ip4+ZI8lCvE2/yLGhsCA/aP7079F8UuR/uSbymGlaiq6oyKk77XvjV6t XL2EPOb0wkVYGs4+F+chXBXPumpdlh0vwGwjBjtEjh6nJQo0izJpZb//oGmplh2ioRFd Rd4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=B3mPwfTr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b10-20020a170902650a00b001bdd58f685fsi3845257plk.85.2023.08.19.14.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 14:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=B3mPwfTr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D80AEC6E4E; Sat, 19 Aug 2023 01:44:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346567AbjHPVkC (ORCPT + 99 others); Wed, 16 Aug 2023 17:40:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239250AbjHPVj2 (ORCPT ); Wed, 16 Aug 2023 17:39:28 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDA9F1FE3 for ; Wed, 16 Aug 2023 14:39:27 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-589a45c1b0fso92343047b3.1 for ; Wed, 16 Aug 2023 14:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692221967; x=1692826767; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=dgfv9XpiXMzsq2kLywbyVX/AZp8i35sYGiNA5Uju+Tg=; b=B3mPwfTrF1Ige4phc1lVSf7W1iqdnDLezfu/Ms6Scp4jsTZmzB8Vfhv4DjxvTlOZcs tk9VlKRIXH/RwiRpno3xlRg+kYX83WMe3fSZqxLsQk8WKCjS3QrUPun6+6rZd3biMiEj ZG5kCeCarobtr+BZHlkQj9h7xwP4ChxqgVGCxRNAks9MBaH2PoN9TO+DMTtcDE8Js0xd 33v65vYmTZ13eJmIkbsGN9AMOKxl5rl/FHmo+ofyFjDDjj5uScL02oYID9O494OUmQQa ZMvGjuUfwo8WSY4vIfUiJkdlTULm7UYdPh65MmP5xyig/2Fz+behqtWgnayNAE3uRygV KUJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692221967; x=1692826767; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dgfv9XpiXMzsq2kLywbyVX/AZp8i35sYGiNA5Uju+Tg=; b=KdEXJSRkwn5Hl7RWrgWU7hF45edXJnMVks4403b756qwIkbSAbfQQwYlAlDm3Bo3Ia TPdSoHOhGF+ZhYK+H4OwTWAG71tdAitDd/SCBcAwtKKj70jFFYjGWI2PkXlYlKEvXALC YTVUMO+YOZY0Ny1B08ZXQ1GnpeLgetwUYBdKWrcmOdO/DeiP39bI/Bpc+ExHaCrzEHxp HL69URMWf3OiFpUcU3IA7QhKthcM9QNRmYpa3HZZQTx9PPqUG6mL+adNTAQ8XTE+/DoH nFcIJ/Z4Dh1ic+QXbQt5c/n0x7XB0EB+GgvP4EAkJ53xe/pWifUvcwFtUz/emb2PhV9R IQAQ== X-Gm-Message-State: AOJu0Yx896amDNK571wMNESKkU7juu71VCu3bzzhd7KQtnnPJprJf6Vm acEEbjgJSmPZEWZT+VEkfNhjjkSKfBj/A1vQ6A== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a81:ae66:0:b0:589:9ebc:4bfc with SMTP id g38-20020a81ae66000000b005899ebc4bfcmr41356ywk.9.1692221967232; Wed, 16 Aug 2023 14:39:27 -0700 (PDT) Date: Wed, 16 Aug 2023 21:39:24 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAAtC3WQC/x3NwQrCMAyA4VcZORtYW5zFVxEPpctcQNuQFHWMv bvF43f5/x2MlMngOuyg9GbjWjrcaYC8pvIg5Lkb/OjDGN2E1rRk2TBpXlHqh1QyyjO1perLUCy gklTjVnXDeE4ux+lCsw/Qm6K08Pf/u92P4wcoxlPwfwAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1692221966; l=1607; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=30eCBoYcInKFNOcnuhFfYjRixFwqc2selXbnOKgw6dI=; b=xDzKLH1yz1jxJwierFXeVLUgiJfBIeQIt+nXl5gaKMxMfmxMDGzOJZDP9cseijM4Ywj0ktUp1 Q2cOTSB+/0pDQWF0iqwsPv7ZIS9SsHY6BJ5okfK8iTSE6218SV8h728 X-Mailer: b4 0.12.3 Message-ID: <20230816-strncpy-arch-powerpc-platforms-ps3-repository-v1-1-88283b02fb09@google.com> Subject: [PATCH] powerpc/ps3: refactor strncpy usage From: Justin Stitt To: Geoff Levand , Michael Ellerman , Nicholas Piggin , Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Kees Cook , linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org `strncpy` is deprecated for use on NUL-terminated destination strings [1]. `make_first_field()` should use similar implementation to `make_field()` due to memcpy having more obvious behavior here. The end result yields the same behavior as the previous `strncpy`-based implementation including the NUL-padding. Link: 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 --- Note: This follows up on a previous RFC which can be found here: https://lore.kernel.org/all/20230811-strncpy-arch-powerpc-platforms-ps3-v1-0-301052a5663e@google.com/ --- arch/powerpc/platforms/ps3/repository.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/ps3/repository.c b/arch/powerpc/platforms/ps3/repository.c index 205763061a2d..1abe33fbe529 100644 --- a/arch/powerpc/platforms/ps3/repository.c +++ b/arch/powerpc/platforms/ps3/repository.c @@ -73,9 +73,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4, static u64 make_first_field(const char *text, u64 index) { - u64 n; + u64 n = 0; - strncpy((char *)&n, text, 8); + memcpy((char *)&n, text, strnlen(text, sizeof(n))); return PS3_VENDOR_ID_NONE + (n >> 32) + index; } --- base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421 change-id: 20230816-strncpy-arch-powerpc-platforms-ps3-repository-85a1c867ed23 Best regards, -- Justin Stitt