From patchwork Wed Sep 13 20:23:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13383754 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C24CEE020B for ; Wed, 13 Sep 2023 20:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=zn7svbpyNCWRRU264e8RORlCxzb7BjLbWP899iztlK4=; b=mY+ Ebi9RcMdUnUkxzHKvEn8qyziKT7t5PhNFxAqLvaBlibPLgaPZhs3ZwwAGSMfRuZNYZAXPWM+KZRWg mumWcS1k+gDuh7IIqCkbP1l51tzG5GY0R5Q0mw1B7ype1aFXzFyQW+bS7ErlDH5lXrfzKlHslHWPX dnMV491oSJ3UrCVRrJ5uPtPwTBu3o7eJPQ05yCLDj1I6WTkcO9kvoIW7kLIjCPcDYEBme08YLap80 aCNIu77BACE0nEjjY6SVJMmHYxD2NVvvJkIT52zMdUrar8D5BY0anPKdMhUmzuX/z+A3NX1j7vJ7u OPGw+IirlsqTX4C2NSVUILjKLyE3Ryg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgWOE-006fds-2z; Wed, 13 Sep 2023 20:23:10 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgWOC-006fd9-1Q for linux-arm-kernel@lists.infradead.org; Wed, 13 Sep 2023 20:23:09 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59beb3a8291so281577b3.1 for ; Wed, 13 Sep 2023 13:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694636583; x=1695241383; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=XLVs+6bnfHlUZtqtSLrfEVAUEdElqt9QJcV0k0rrN6k=; b=G6nGu4eTCWPPiTIqzrs5t0cy9DPBLqii68l5KsK4zqKbpHFcm2SIqVGUVXHlXHnPR2 3s4qNv+IAnSAsFaMqsAZcrX2icvd1A6VEW36bURyu1nrXAGZAC/0lp6UfIAjIWLYYVh2 Cl0sDGLOCbSCSZE4Z0U2hchFHfymWUwdHtjlDnvq0BvSin4smQf5PF7s27+9V52QKKzf Jd9bgkyN9knF9+8dnsD4x4tlPbPODDhDemWX11B22mDSShGJ/ezri/2K1PU+vo1X8CnT PxuVvQmEy0qOAJPBGQWt/QOrVPxnee+yNA8sb1pUGvvyyIg+fqAGz8yb0kImoP+K0SX7 ARMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694636583; x=1695241383; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XLVs+6bnfHlUZtqtSLrfEVAUEdElqt9QJcV0k0rrN6k=; b=RgNL5OiqggLu3D4+5+wZTG/Q4o7HWStITR/xlzQT50gzoKz4w3z2aPsjz+D20dv0oA o8J70c/pHh5aC94hHqEsM7haJK1IrxnzuzfkSg3V1WPhvHKMOw2hAOh1vyymzrIEgfQe F1cijIw7gCjnx8v/DEdQV8OsfdT2yyXlGPtC6zN5L17OhJbWLDtl2x0DhJseturyogw5 Idlno+h/jMKAXRMYS4W8qzkRVJ5ObG67VbRrH+PhRo6Rm388inDPppZJeSxghgCiU6Ds yevYIJW3Q/K+9Hzr7BxykO2tzrZPHiQg6EoNqu0enhrUcFPXJoMYDr17rSpRcgvirUoA FarA== X-Gm-Message-State: AOJu0YyQVqeS9OM7ALH3sps3Gi9lrjyiz6S7kvFNXhjIsAscsKpNoVoc S7Peu4SbAWrIpe0IIeK3Isu1nFHcm7+Iff5OwQ== X-Google-Smtp-Source: AGHT+IH6PBuI/9PEyPLMURyvaLd2wWJ5nq4Nq4LzMK+VjpjvcMFoH6Veim3KBZowhXINgmUEpT7BsE4SUJC+BkTBkw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:690c:3108:b0:59b:e97e:f7d7 with SMTP id fb8-20020a05690c310800b0059be97ef7d7mr10791ywb.1.1694636583064; Wed, 13 Sep 2023 13:23:03 -0700 (PDT) Date: Wed, 13 Sep 2023 20:23:02 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIACUaAmUC/x3NywrCQAxG4VcpWRvozJR6eRURKWlG/4VjSUpVS t/doctvc85KrgZ1ujQrmS5wvEtFODQkz6E8lDFWU2xjas8hsc9WZPrxaFjUnDPs9RlMecbdBSw cY98fu5AknDLVzmSa8d0f19u2/QEyILlDcwAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694636581; l=1662; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=SaJSLsGfiwN8Z9qDzVTnJDfBIIvce2p/HX14tKRLMrc=; b=isyfhr2IybzgbSgYpUiLNvFNLLapon+q44khS63C6lQdJpD07Owf7rFKWlnZSjXr/pvfX+d9M 0S8wXWPqEHHC6Q4LPImWcaxPhpnnxPUrHci8d0JQRBWvVp9SeWxgjZZ X-Mailer: b4 0.12.3 Message-ID: <20230913-strncpy-drivers-firmware-ti_sci-c-v1-1-740db471110d@google.com> Subject: [PATCH] firmware: ti_sci: refactor deprecated strncpy From: Justin Stitt To: Nishanth Menon , Tero Kristo , Santosh Shilimkar Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230913_132308_484717_B0EE2A30 X-CRM114-Status: GOOD ( 13.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org `strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer. It does not seem like `ver->firmware_description` requires NUL-padding (which is a behavior that strncpy provides) but if it does let's opt for `strscpy_pad()`. 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 Reviewed-by: Kees Cook --- Note: build-tested only. --- drivers/firmware/ti_sci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec change-id: 20230913-strncpy-drivers-firmware-ti_sci-c-22667413c18f Best regards, -- Justin Stitt diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 26a37f47f4ca..ce546f391959 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -485,7 +485,7 @@ static int ti_sci_cmd_get_revision(struct ti_sci_info *info) ver->abi_major = rev_info->abi_major; ver->abi_minor = rev_info->abi_minor; ver->firmware_revision = rev_info->firmware_revision; - strncpy(ver->firmware_description, rev_info->firmware_description, + strscpy(ver->firmware_description, rev_info->firmware_description, sizeof(ver->firmware_description)); fail: