From patchwork Thu Sep 21 09:58:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13394229 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 83A1319BAC for ; Thu, 21 Sep 2023 17:49:52 +0000 (UTC) Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BE2D93D4 for ; Thu, 21 Sep 2023 10:31:20 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-690bcc80694so1268983b3a.3 for ; Thu, 21 Sep 2023 10:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695317477; x=1695922277; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=UvRP2TfqMYoWryE4cjFQULg+pydcORb0OjXIUY1wqrk=; b=g9KepjurlkFwWTXiywPcF/rdDrQqWCCJVvoNdO3XpsIikTrOmUR+zGVNG3d59F34dm bl26hRC/xJxtBg1Y5123oXcUC+s/SLKcBD674gajl9sN3JzhAhJDuGoop/iYnAQQ/zEa gvU7vCAuqoqpcvItRS5RS+0P0vNHcIuiRy9Vl32UPr0IEAqu+s5RYDcwsBCu+EybnGpx fwYCy9b1vP5k9tB91/WUHJ76xZN+vSh/WbqM0nBmtxWmQwRri70m3vU//G7fZiQTc4j/ YDD8+rAIgZoZ+eEu5Yofk87Kts48gfIS8qaDYNSx61Wtdy2FQ6dLVaZCJuqUOWY+D+Ro lPEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317477; x=1695922277; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UvRP2TfqMYoWryE4cjFQULg+pydcORb0OjXIUY1wqrk=; b=iVP7TWcggmmMKQMwXGPQr1h5gZj0+7MXy/ET+FyxVu6/VRRFGJ9fh/53Bg42ZzNR5x mgvuz5xouoSRKIA4LcNVFpAC4QpPX3SQVSonBuEmCmpzwJdpSpPeYmSvyyMzfCQ8gfMG h2IWzva1GPaIxPBvI30mjH0hn74ahVqqZ6Wsw6JZzhxVpvabbosO6lz5+BZ8zIkhYyO/ ZptBe/bCaKrjXy6gwRIwGgwXqwbBbIMNWnVnxvdDkiwSQorZCBWa0QizK5pIvKxNM6vJ GR7qzqwEPsSY3EgO3DumuwbJltKUeZM68nm6BgRtpY+laFkNqyyfsk7b2VD/xxmG7QmB mQHA== X-Gm-Message-State: AOJu0YxH05NQuNfraQAMpABNy8cxFV6F+lKzzutikWQhanOIEXsjIs92 +rGk7M9KIqa+7j+hd+W3Dddp2BHaaGdOMovjkg== X-Google-Smtp-Source: AGHT+IG2Yj4B6f5Tc0Rfcf05CQVFSDA0RjwtjZ26D7TwaHMo12AIN3tJQTbDdw8rZkT3SSBitMany2q06U1RnGKdFA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:1704:b0:d64:f7ec:6d5d with SMTP id by4-20020a056902170400b00d64f7ec6d5dmr74413ybb.10.1695290292498; Thu, 21 Sep 2023 02:58:12 -0700 (PDT) Date: Thu, 21 Sep 2023 09:58:11 +0000 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIALITDGUC/x2NywqDMBAAf0X23AXzqKC/IkVCXOsejGFXpUX89 8ZeBuYyc4KSMCl01QlCByuvqYh5VBDnkN6EPBYHW1tXt9agbpJi/uIofJAocsr7hrKwvzFMzmN EH5rWP51pIgUoqSw08ee/6V/X9QNQGac9dgAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1695290291; l=1427; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=j36xxcAKXhVsbdky0Obg3UV1f7PgSu4ObXF+TdHlQCQ=; b=Pb35PYt7fwpSsE9B2qcuVWUq286nCf7oXfw7i0nvTKQhWQ6J+VwYyKR6k0TFykxTVFMxIx2xi 11/P/koHLdmCZR549wEcVOW/DbyUc2TtEX9Y9vD/emSCyTPjYvAmZp9 X-Mailer: b4 0.12.3 Message-ID: <20230921-strncpy-drivers-input-rmi4-rmi_f34-c-v1-1-4aef2e84b8d2@google.com> Subject: [PATCH] Input: synaptics-rmi4 - replace deprecated strncpy From: Justin Stitt To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DATE_IN_PAST_06_12, 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=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net `strncpy` is deprecated for use on NUL-terminated destination strings [1] Let's use memcpy() as the bounds have already been checked and this decays into a simple byte copy from one buffer to another removing any ambiguity that strncpy has. Link: https://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 Reviewed-by: Kees Cook --- Note: build-tested only. Similar to Kees' suggestion here [2] [2]: https://lore.kernel.org/all/202309142045.7CBAE940E@keescook/ --- drivers/input/rmi4/rmi_f34.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: 2cf0f715623872823a72e451243bbf555d10d032 change-id: 20230921-strncpy-drivers-input-rmi4-rmi_f34-c-4a6945316cea Best regards, -- Justin Stitt diff --git a/drivers/input/rmi4/rmi_f34.c b/drivers/input/rmi4/rmi_f34.c index 0d9a5756e3f5..3b3ac71e53dc 100644 --- a/drivers/input/rmi4/rmi_f34.c +++ b/drivers/input/rmi4/rmi_f34.c @@ -471,7 +471,7 @@ static ssize_t rmi_driver_update_fw_store(struct device *dev, if (buf[count - 1] == '\0' || buf[count - 1] == '\n') copy_count -= 1; - strncpy(fw_name, buf, copy_count); + memcpy(fw_name, buf, copy_count); fw_name[copy_count] = '\0'; ret = request_firmware(&fw, fw_name, dev);