Message ID | 20231116191336.work.986-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp56296vqn; Thu, 16 Nov 2023 11:14:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEy3YPYerrVfBVHwpkMW6N7ev9CV0AxRwjhirkwFY8y3PinVJzzpzvyDgBm4t9Jq0+cetYj X-Received: by 2002:a05:6a20:7293:b0:186:a0d9:4189 with SMTP id o19-20020a056a20729300b00186a0d94189mr13944710pzk.35.1700162051025; Thu, 16 Nov 2023 11:14:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700162051; cv=none; d=google.com; s=arc-20160816; b=bf0ifv5Fcvp84oPRxmz9vxu5xh9bqBhiZ3BskwUhll0H+NgDkD+NgQLZSPAUvcRH31 h/Df46oDucWzRJTr8u45PmQ1YqEE8ic6QIAumuBelCzNZrQ0zi1ymhrds2muD0Mjg9LJ AxBEOv4xGn4MJmPBQYjT48cZu081DULSCzpxe4BNrPQvhtTHe5tBK9p4ujdkZb/rE0wB f0IvfuSzs5bvJPCXIin4Y5quaR2Dty7V/6lpyzq4L7NalO71YK/Mkabx5jtonG6t+QlO z/8H+HGuABL6/A2J3/P9WUEpzL+CmWKoEc9chiaCk+p3WAVjwlFU7byIH5TlzqSX5eCN R9ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YYlw/v9GVrPaC0s5UN9J8tYY4w/hsJ/PA3URh3Q8lJ8=; fh=TEsXOOFywEdP0tuEsq4mymOJ9nFpq680r47OXor1ezs=; b=0x3EAQxpyE/YD7wHGPLsnTdkDAvg7YbFOlLKL2cWTsviiBAryIdMdGTCU5JzVS/O8Q GPaoF6vt8obIpQmJIRDZ79BvOK+M8tT/eBb89QTRNh4i7+AWU7CRra/BMeL/eiB6H5/t +o/x2NkxNVVKacz4QF4Gmz/3J2O0opZiKvw/Bq6aKkSOF5hdF0ewIvW4KExgsPxviv65 puEodd0aO89qQmRuw2yjH8V+jKDV1PdPnkiuI6UA0oeeQ3ypwy9QqFXwoc6GOC+mNGyI nyHT8cNmPSyE3QWMnPVyW6XxAYFfzoIoeGE2NABnXWx1TNpjvq3u7V+6xYlMZeovMth3 9FUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VooWjFQE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id e20-20020a656894000000b005b8eaeabf49si119428pgt.178.2023.11.16.11.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:14:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VooWjFQE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 8BBB3803B72B; Thu, 16 Nov 2023 11:14:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345490AbjKPTNt (ORCPT <rfc822;jaysivo@gmail.com> + 30 others); Thu, 16 Nov 2023 14:13:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbjKPTNs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 16 Nov 2023 14:13:48 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E84918D for <linux-kernel@vger.kernel.org>; Thu, 16 Nov 2023 11:13:45 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6b1d1099a84so1128919b3a.1 for <linux-kernel@vger.kernel.org>; Thu, 16 Nov 2023 11:13:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1700162025; x=1700766825; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YYlw/v9GVrPaC0s5UN9J8tYY4w/hsJ/PA3URh3Q8lJ8=; b=VooWjFQEZrJhPPuYBpbhtwGwIQgYGz6kH0inZ+g8mS1ynD+fdwb6NjYBvWs9iWLgRA 9ik1hqeGW392s0wHuBgzAVv4Xio9IUo+99d0h2n98vq8bpiwCBIJ/zqooC//Mm0N22HC L067ds04wmKvRFf/0yGr9nxObGiDNf+s7KhrQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700162025; x=1700766825; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YYlw/v9GVrPaC0s5UN9J8tYY4w/hsJ/PA3URh3Q8lJ8=; b=VJIWo0ecG6mGgc8cBb6WqzRKOeVbaBkEZ8pwMIgFrL6IrNf6GkkLQ6lbWVECxOAqjT vun5wzW5PzomSWHR566e0mwMu0buFvBIA3crFf+VTrHa+nP4/27ZnkWoaurfC/L4zbzx OvjXcKR6PqtH1H8QVF2vj2NFyDMIo28A2l16oavRgJuY5T3b6UpgoYoa6LYTbznTQQ5I T7HQ5zes0Sj2QV+5bvYFZeoZ2GFKfvgLkBVnf195TFy0iNw1xCk42UTbZ41GLKL/IRU6 VOxqboBnl4z3zpvSOhAn7g+vjXettd2Z/74OB2Knh3evr/Cbszy0UHcAErvouCz5HbV6 u6GA== X-Gm-Message-State: AOJu0YxfjKidu2AsWypE4P3kG5Lxt2rCRsxeTD/J/nHRbZdAELaMFrlv WuTzUm4EBDCNgMqjohLp/xsUyNNqzLHiiv0qfNddvA== X-Received: by 2002:a05:6a00:4099:b0:6b4:231b:a45c with SMTP id bw25-20020a056a00409900b006b4231ba45cmr21865074pfb.26.1700162024994; Thu, 16 Nov 2023 11:13:44 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id p11-20020a056a000a0b00b0068fb8e18971sm77330pfh.130.2023.11.16.11.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:13:44 -0800 (PST) From: Kees Cook <keescook@chromium.org> To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: Kees Cook <keescook@chromium.org>, Helge Deller <deller@gmx.de>, Azeem Shaikh <azeemshaikh38@gmail.com>, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] parisc: Replace strlcpy() with strscpy() Date: Thu, 16 Nov 2023 11:13:40 -0800 Message-Id: <20231116191336.work.986-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1424; i=keescook@chromium.org; h=from:subject:message-id; bh=BzD7pn1JfYRhaoY80hkyIKEr+mEu4xES2K8u21WGIyk=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlVmnklqIN5lZaW0f7xYsyH3WQSBx8zE4Qk3JQ/ qbccTS4bEWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZVZp5AAKCRCJcvTf3G3A Jnc2EACuCUkbrGx9lSJGiaQGUafTwnelfTeuI404evq3xhBAjJHJhJCJ+uvTDfi1Pckk2n1LUMD QXo8pj48wa+jy9NQ0Q5+RSxyunjEvpbMaTRjmoVF1rlSMM42iCMihT/xBpWAm7LC8Gxr1551HxM eJ9I0uEQz+/MdFjBtxRO7YC2HAcwGsvuIrD5hHXD2mm4PbdQ8KdnoGY7iSWBpXd59Dwc+2V3DsC GrZTQ7LpjjsfziVRhVi7NmwSKE3FfcSd8fv3prm/DJl3SUAABh7IZFP3JvaSOG6oh3cP5lM2VzV 2JKNorakX5VGe0Lq9GYpFGY4+XEkLljxIvYXYkgxjnbhM0KtRzB3mySyTAVMiRWOGzh0cJX2+KA 8648KnwAHCIQKaOiY4wmF9YraK4DvjN8PTn38IXBQHipgJRXnXzbnDV9FybPxIeGdGYWPddV0/t SW8RXJ1Hv45wcANMdcpQ0g/6ZefeupFqVhrooMYOtnDIJUPAI0zSTLY44X1g/p5+LDIcT3VRyKz tqDDQx4/rU0UKiq1Y7V1vV2XtRJUHOIzJFdrSFaZCR655E2EaMqtHJdA612nQpspQl00NFCnmuH lBR2AZwCTYXLXJM2ia3p+h88JWMY+EGFjyBzF9P0yPp/IlqVr1v/sTnCrjdHTArUtOo51sDYTUm GjKamcX 6VghP7eg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 16 Nov 2023 11:14:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782749122617345721 X-GMAIL-MSGID: 1782749122617345721 |
Series |
parisc: Replace strlcpy() with strscpy()
|
|
Commit Message
Kees Cook
Nov. 16, 2023, 7:13 p.m. UTC
strlcpy() reads the entire source buffer first. This read may exceed
the destination size limit. This is both inefficient and can lead
to linear read overflows if a source string is not NUL-terminated[1].
Additionally, it returns the size of the source string, not the
resulting size of the destination string. In an effort to remove strlcpy()
completely[2], replace strlcpy() here with strscpy().
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [1]
Link: https://github.com/KSPP/linux/issues/89 [2]
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Azeem Shaikh <azeemshaikh38@gmail.com>
Cc: linux-parisc@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
arch/parisc/kernel/processor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 11/16/23 20:13, Kees Cook wrote: > strlcpy() reads the entire source buffer first. This read may exceed > the destination size limit. This is both inefficient and can lead > to linear read overflows if a source string is not NUL-terminated[1]. > Additionally, it returns the size of the source string, not the > resulting size of the destination string. In an effort to remove strlcpy() > completely[2], replace strlcpy() here with strscpy(). > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [1] > Link: https://github.com/KSPP/linux/issues/89 [2] > Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> > Cc: Helge Deller <deller@gmx.de> > Cc: Azeem Shaikh <azeemshaikh38@gmail.com> > Cc: linux-parisc@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> applied. Thanks! Helge > --- > arch/parisc/kernel/processor.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c > index 29e2750f86a4..e95a977ba5f3 100644 > --- a/arch/parisc/kernel/processor.c > +++ b/arch/parisc/kernel/processor.c > @@ -383,7 +383,7 @@ show_cpuinfo (struct seq_file *m, void *v) > char cpu_name[60], *p; > > /* strip PA path from CPU name to not confuse lscpu */ > - strlcpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name)); > + strscpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name)); > p = strrchr(cpu_name, '['); > if (p) > *(--p) = 0;
diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c index 29e2750f86a4..e95a977ba5f3 100644 --- a/arch/parisc/kernel/processor.c +++ b/arch/parisc/kernel/processor.c @@ -383,7 +383,7 @@ show_cpuinfo (struct seq_file *m, void *v) char cpu_name[60], *p; /* strip PA path from CPU name to not confuse lscpu */ - strlcpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name)); + strscpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name)); p = strrchr(cpu_name, '['); if (p) *(--p) = 0;