Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4777866rwd; Tue, 30 May 2023 09:43:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Oby3tjAhruIeFcKVjxd0tGZq5RdeotCVoIMAiaAHOYiNZ3P3n72YSzLphSPmJhiVYF+7u X-Received: by 2002:a17:902:d48c:b0:1b0:3b07:705b with SMTP id c12-20020a170902d48c00b001b03b07705bmr3289979plg.7.1685465001967; Tue, 30 May 2023 09:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685465001; cv=none; d=google.com; s=arc-20160816; b=PH9JynuF8xodJup7n6D3VIe9XkurqKA4rn5r/3VEnk2eHs87gm+XdF0Ske6jfrLYlr JRQlrpcAguCQi1uWyS8VxybhvVe5rIqazaZPQENzgG1rqpUsf/ZKHKpc/qH7dKdEqBQL AA1OQV8W4BJNP6+7CA6mV5F70n+38eEZgMa4Ihl6b83Cl3VDuqhZf1fdL/zlNDT1MNun 9fPpJG1YCA8Ao5GQ1FG1ORCG+2Ha0NN0lAtzZl6ukfqQ+xibb+eRX50pKZi/kJmUSCgS UKrJUCuo3gTYe0KvS/oa1CEb/qnnM+4aUoTIsSlEQ98X+FAipcRuJPHPNk1z8CQQWJzu gkiQ== 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=IMjYKQ2PlZitUpCphm+vKSc5wezwssaSZO31t1ueH0c=; b=hOpVsW5PSLylOnyblyPjAnrrw9l/7x213nkPoRUARGmbxHULetXPxRUynjlr+rXYxt 2mbkxTDlvVYmwebZEQ1Fgk0RiaiiJYA7FlWq7E5uHf6juLpL2N7Z/anqvyFp356vJxez x6YrcunZfYFSbzzOQ9gie2ITHSsMx4Ge5SQ+ykw8ZKytqb9bRUvc0tu7s24T25URyTn4 TmktHsI1johFkaWQvaUgacjrJdgXNQMcd+01g2LKq9Mv8NLP1qyBEEykKKsOsrcdZVCc beYX/kyNJi11VxuwLjCe+JyUDSOBgYnyJ3LFDv0HpaQIIwXGaya7JNu5uaSV4DAw1RPR OQ0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=r476RQSd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w23-20020a1709027b9700b001aaebc66877si11231145pll.147.2023.05.30.09.43.08; Tue, 30 May 2023 09:43:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=r476RQSd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230143AbjE3QgO (ORCPT + 99 others); Tue, 30 May 2023 12:36:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbjE3QgL (ORCPT ); Tue, 30 May 2023 12:36:11 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C035D123; Tue, 30 May 2023 09:35:50 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-39a3f2668bdso540114b6e.2; Tue, 30 May 2023 09:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685464550; x=1688056550; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IMjYKQ2PlZitUpCphm+vKSc5wezwssaSZO31t1ueH0c=; b=r476RQSdTR6xTXIl/DE6+1yq3sBfoNAJfwfKe+zjzaVW+ei0z8JZvo5gAURjHWmfUl x+1IEAOAwLtt9iIybFCimHLWnZsXDtr6b3Q4YoFykth3FXWqZ15b32vib2t9Tw9iy+Yz yyglPe7G4b/gyoORnL8TDiKsI8yYfHo6xzX1jNtggXK5Nb/W3S3e9ZuXiZl/Qov0KNSv anr7zuy9g9Jp5TV63Ub7dJoQDE7LPsPNo0Bg3wHPLLdcWTiK0zzNneY8mVK2mF4Q4/Ty RqY0MxtJafogVr+vgly2hE9u0pQkgCW2mTvBttD2ceEmLT5Nm9eaVRpWrKHhAuzHW7v7 qNeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685464550; x=1688056550; 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=IMjYKQ2PlZitUpCphm+vKSc5wezwssaSZO31t1ueH0c=; b=kaVaRZzZjcYN6XNLP0K8aRirkPutK/2FOMksIb/dj4G+swXVyBFJvZsf9VC3s8RQoc Z+8djBbGGYBT7+V1WRLV4Cv1DlhBCxcURBmxWEYSNHNcRVA5p0RZ05FZoQBn3oynXSTg XBl7NRzJXS7KX04XQINnDZVECudQhbKmPGh/Gqj+iURVKtmI7mEY7aBWWPSKCcDHCVmP gi5AtRoRCTUD4w3X/43CwUh2uO4qLoyjBO8lcSolPY7BkdvaJaoZMm7hFnPKx6I9rOmv LkVFa5igoHs7+UxFmIr9eYYUEoVMKvNJnCnUJkqiOyNjr71uw3M3XPYiwPi7M4w89dpv /TWw== X-Gm-Message-State: AC+VfDzUm8xpOS3/T5JphDisWUz0dMggutjt9YzOPjwTYDbA5y3vgeqh RZispvpOLLK0hHIhwWu0ReBjVezAPN3QnQ== X-Received: by 2002:a54:4e83:0:b0:398:dd2d:b114 with SMTP id c3-20020a544e83000000b00398dd2db114mr1337550oiy.58.1685464549833; Tue, 30 May 2023 09:35:49 -0700 (PDT) Received: from azeems-kspp.c.googlers.com.com (54.70.188.35.bc.googleusercontent.com. [35.188.70.54]) by smtp.gmail.com with ESMTPSA id co17-20020a0566383e1100b003c4e02148e5sm803901jab.53.2023.05.30.09.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 09:35:49 -0700 (PDT) From: Azeem Shaikh To: John Stultz , Thomas Gleixner Cc: linux-hardening@vger.kernel.org, Azeem Shaikh , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH] clocksource: Replace all non-returning strlcpy with strscpy Date: Tue, 30 May 2023 16:35:46 +0000 Message-ID: <20230530163546.986188-1-azeemshaikh38@gmail.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 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]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). No return values were used, so direct replacement is safe. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] https://github.com/KSPP/linux/issues/89 Signed-off-by: Azeem Shaikh --- kernel/time/clocksource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 91836b727cef..88cbc1181b23 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -1480,7 +1480,7 @@ static int __init boot_override_clocksource(char* str) { mutex_lock(&clocksource_mutex); if (str) - strlcpy(override_name, str, sizeof(override_name)); + strscpy(override_name, str, sizeof(override_name)); mutex_unlock(&clocksource_mutex); return 1; }