Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4726894rwd; Tue, 30 May 2023 09:03:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6tVn++7UKVmM1VvIFDe6iz2r6Dg+RC48fdGRcGfIPojqHqqCUtTYWIfGn0TkQvKWC/Xr9y X-Received: by 2002:a17:902:c3c6:b0:1af:bade:2b0a with SMTP id j6-20020a170902c3c600b001afbade2b0amr2473882plj.3.1685462633882; Tue, 30 May 2023 09:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685462633; cv=none; d=google.com; s=arc-20160816; b=Uh5V5ytaNNuIkU2FcXOFzNYk4YzUVZyw97C/Qfr9IyOPk88ANKIgBSeSLhs15BBvGu 1Owr9CtIsCyLPsfx7cPjZxU9d1xO7R3sE4a4yAVw/NL6WK11Fdln9ngpN6mmqhSFAXy6 B9AZuWN0NJToUJPeRda8wjDTBjKeQwh5AKVgLzXt725U28ryMK2iUj+57sZ6MreDq1DK nEijWUNxTpuDKPZVkDRCdO8CFwtBAoznhesZr8CQySVx9T4QzwluMBUNWEO8Kmbbcr5l vVU2a9wBphV2FNx3yRAhU1xrIXUfGpZPLvdlz+2i8CtsQy01+rqPqrPaYsVpOuc+74eR 9CgQ== 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=HzLXJzmyM6ehvjxPhXBctuD6pzz/uhWxjF9MwpFFoX8=; b=oyVXB0J7XLw8/l5oqKaFIF5NiIxsj0Jo9hCcKtBBYOeS8UtWwUhzqlNztpgDOedWj7 p9TU5AbaJEeF2GHX7mMt01RqR+zJFg/YiFojiH3MRrfBK3uau/8o4FK6Ko3/76/U4QYM vql1hZFECUjTI8T2lVDABCVk28Q2MfP+FUpF69IJwfTdSZfpBTPaA4CmPJWXXsXC1XAj 8tBnxDTTtUcJVb29CmRFR6r3s9mbB0ynXxlW95r+mFnzQDTwTqb7kDP4iabheWdRO96T o1oHnMEtxN88t5c6ed9MiPjvAgDb8ih9AQ0GymeGh/VtIyotFbzq3TZnu8go2yBxKtGu pSAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=sV0vVcLu; 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 u5-20020a170903124500b001afe1f44c02si12283701plh.60.2023.05.30.09.03.37; Tue, 30 May 2023 09:03:53 -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=sV0vVcLu; 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 S232854AbjE3Pzf (ORCPT + 99 others); Tue, 30 May 2023 11:55:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233196AbjE3PzV (ORCPT ); Tue, 30 May 2023 11:55:21 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13475C5; Tue, 30 May 2023 08:55:20 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-77749d2613bso54105039f.2; Tue, 30 May 2023 08:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685462119; x=1688054119; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HzLXJzmyM6ehvjxPhXBctuD6pzz/uhWxjF9MwpFFoX8=; b=sV0vVcLuN/c8aFPDkzIKiJQGt1mMSPXwASTgM7ibpdqLu4XwGviCTR0sJaE6Y85YEg Bk7z2RgujlJJ+T1mrbGiKUMJfbJNJ6WluHksu1/z3i5GqWa4L2bcSE97wFUpz7xqde+f E7lUcUasW1cgj0yw2wQW10mE5LRvZB3IiOmCEBespXbVIN+QAJi6naMhwHctPslZorCN q+Hl9sDTFvNL+xYcyznfDt9/xiTcXZQ8NYW1lZy55pfHhzvDuKKt+mYd0B1Jj2SwjUuH ArEfKy+j/WGPnA5tlsZybGYerz7mnNAIlT8PG6qSpI7cVgTtBY4Kw9W//qEHQwLRHKkz S0Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685462119; x=1688054119; 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=HzLXJzmyM6ehvjxPhXBctuD6pzz/uhWxjF9MwpFFoX8=; b=Qt9z5yYKQKo6TCddR1hg3c/UPLIWE+ACIAOCQFw8BwcvH4uOUdLrhGjFnvBQjTHEZd gx6DEP3usbDKHNef3jJQpwlFVyRDTpL+0UKjLnSfUA0ZzcDapnDGdNJVAgSzr3AhS2as 7XTPTvUnNXWuMqF+6yoqqIRNiPfR2GDPPG4HYwo1rajgpm/rMx970oTMLUtTr1gTdhyZ UF5gh4Mnet0hhQXRYPVJO9Zc3nl5dcBdKi56jRoFZVCKzEG5rBumiUqdL8J+hr8jBEjU X7e/XiF6zJM40ZFhMDZznPgjJpsLPeDtdnul3hl/SLDyR+s4RvHkDfXHbqpuEXgp37Z/ ZobQ== X-Gm-Message-State: AC+VfDzQUEHjZqBk8OCm30V7qVX1FaNUKQI46956EcIKV7s/r28KFN2P C3DPffgRJ7MDOM6EFOEvX34W8NVPGkc= X-Received: by 2002:a5e:dd07:0:b0:76c:89de:ba47 with SMTP id t7-20020a5edd07000000b0076c89deba47mr2064040iop.19.1685462119157; Tue, 30 May 2023 08:55:19 -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 ct13-20020a056638488d00b0041ceadd5f4dsm743187jab.70.2023.05.30.08.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 08:55:18 -0700 (PDT) From: Azeem Shaikh To: Russell King Cc: linux-hardening@vger.kernel.org, Azeem Shaikh , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Russell King (Oracle)" , Linus Walleij , Amit Daniel Kachhap , Ard Biesheuvel Subject: [PATCH] ARM: Replace all non-returning strlcpy with strscpy Date: Tue, 30 May 2023 15:55:01 +0000 Message-ID: <20230530155501.222213-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 --- arch/arm/kernel/atags_parse.c | 4 ++-- arch/arm/kernel/setup.c | 2 +- arch/arm/kernel/vdso.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/kernel/atags_parse.c b/arch/arm/kernel/atags_parse.c index 373b61f9a4f0..33f6eb5213a5 100644 --- a/arch/arm/kernel/atags_parse.c +++ b/arch/arm/kernel/atags_parse.c @@ -127,7 +127,7 @@ static int __init parse_tag_cmdline(const struct tag *tag) #elif defined(CONFIG_CMDLINE_FORCE) pr_warn("Ignoring tag cmdline (using the default kernel command line)\n"); #else - strlcpy(default_command_line, tag->u.cmdline.cmdline, + strscpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE); #endif return 0; @@ -224,7 +224,7 @@ setup_machine_tags(void *atags_vaddr, unsigned int machine_nr) } /* parse_early_param needs a boot_command_line */ - strlcpy(boot_command_line, from, COMMAND_LINE_SIZE); + strscpy(boot_command_line, from, COMMAND_LINE_SIZE); return mdesc; } diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 75cd4699e7b3..3048a685ea79 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1142,7 +1142,7 @@ void __init setup_arch(char **cmdline_p) setup_initial_init_mm(_text, _etext, _edata, _end); /* populate cmd_line too for later use, preserving boot_command_line */ - strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE); + strscpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE); *cmdline_p = cmd_line; early_fixmap_init(); diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c index 3408269d19c7..f297d66a8a76 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -135,7 +135,7 @@ static Elf32_Sym * __init find_symbol(struct elfinfo *lib, const char *symname) if (lib->dynsym[i].st_name == 0) continue; - strlcpy(name, lib->dynstr + lib->dynsym[i].st_name, + strscpy(name, lib->dynstr + lib->dynsym[i].st_name, MAX_SYMNAME); c = strchr(name, '@'); if (c)