Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4896039rwd; Tue, 30 May 2023 11:26:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48sSzDPzmPkK32Z5nup4SLVaYLPE9keFxhTZ+iAXmOTAOtcAXqDeYy/YcSNGWVJJRPwzzg X-Received: by 2002:a17:902:758e:b0:1ae:10b3:6203 with SMTP id j14-20020a170902758e00b001ae10b36203mr2805624pll.16.1685471196716; Tue, 30 May 2023 11:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685471196; cv=none; d=google.com; s=arc-20160816; b=0aOuPWjEiwzAvgt96j46MaWDTg3YQZGXJufzXTg/NULUjdcB+2qJn16JToXeJ8wzhs GAn0sfPgvwfCcHq5UrvWGv8xT5XiHXDJZUt2jvysmwx7zzhD4HzdzJzRooXEMNzkEE+E uRaexOhAgnqO7BOMO3teBlQvAxtep6FqguQUZI4wCTKdQdYp0sVl1DFCt0yTQipU97t6 fBLrfuQsEk00tlDb+Wn6Ptdp3AUVPH64j0MZDzXqHZQKXocYuN2SibaajIkGU72wYlGY kiPjUEYbHpErtXVB/B8ljn/XdXYZcV/MJdJACsvBuXD9zB6o8va11DhEmueP6xmJ8/Ct BWbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=2kVEj843CHgMv+dCunk1UqfhchtPivldBaBOHjhNqio=; b=g/B6/wby5OJmq4ueVcUDPgynfoSJ3VUzhDm07YG7DWkwbxVGbLoo0EjUhyV5CF6hWK PhD2qyPVbs0tc9/DFrY4nkQfSedA7r3FlsJ3s94P5Ry3TGhm4/K7rN8ZCEwhJorqPqgZ fNP7HlMswtpC7ddvmmWI9iAtBplkLAUKuWgVkGXMU3tmnHUm612FXjwF/UlurPTQ5CLB Li7yHKWfQHG7YMzrrCzq+v1PYKEYQh6ir9UPM/zsP3OtX0oH+rpQITcZNWxL47Q0VQqP P3BHQ4778QTq0K7NJGhbB8TFiIHEWReQC3KIGvDzGqyPHIR2metKRvPbyiW19DHagGPB vD+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=rnWe8N6f; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020a170902e81100b001b03d543548si4483420plg.344.2023.05.30.11.26.22; Tue, 30 May 2023 11:26:36 -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=@google.com header.s=20221208 header.b=rnWe8N6f; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230399AbjE3SQp (ORCPT + 99 others); Tue, 30 May 2023 14:16:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbjE3SQn (ORCPT ); Tue, 30 May 2023 14:16:43 -0400 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5DD4B2 for ; Tue, 30 May 2023 11:16:41 -0700 (PDT) Received: by mail-qt1-x82a.google.com with SMTP id d75a77b69052e-3f6c6320d4eso25611cf.1 for ; Tue, 30 May 2023 11:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685470601; x=1688062601; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2kVEj843CHgMv+dCunk1UqfhchtPivldBaBOHjhNqio=; b=rnWe8N6fmz34Nmj+miuUcbtMxa9WO2Cj/nDwQB2qMId4XmWz3ogI6p3hfvx/IQrQmS Q8i1Epz4HuCdfp36ZX8Jin0/6IqdnA4tfslHqab/T9b+yOOjm0giF1hQTvj7/lapmveN /VcdoKqz7w64cvtCPxCxgv3Kr7Q9poRd93/DnBbD4WYi5mNi3lPW0SjofhVSMy1QIx+G 8AsfJhVB9WP3Njgjw18Y1UD6c07Jd7OrLzTFYs/ZCUxbrrKOoEhMLSZp0ec+Zfa8zUub sX/pFd/9liMPgrHIqwByJZm3CqX6nJaGNTXhlonC8E8rK7SVR1HTlMUMfZCZ/8HVoYlN oa7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685470601; x=1688062601; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2kVEj843CHgMv+dCunk1UqfhchtPivldBaBOHjhNqio=; b=KkXKWrcXiIYyVICIOerJ/DSggKgdntbcpFsqp9VWmgWXZMzFSYCAJ4a6SZ2c+y5tB1 49iUry4gCBloGjB6bxcT9oHyoqEj24K/OHM5BEcjkB+YqJkpH53nJAuncVC+CELwKzB4 14Qa7PtBjAtxb/z874kk8H8CbTo29PdAcBEwf84ppIEWV7GdExeiuh1kDZAixjF3KokZ O6fBpFlnfHeEgoJh6H5554ZLvR3vcu1//1/LnEGwDTxK7XjEM7NsgbkcbCgR0KYcL7xt 1fQDOoQY+9V2LQE5TFQq2l2PfOnE6C5v8+Y9aFhUOEy6gabYGBOdhZL+Wzt7W5lq7nF1 DAqg== X-Gm-Message-State: AC+VfDxpExzt93Dc+PXwpJS595N+SZ8lu1BDPY7uhIMxt7M1GQhynsOM hs9D2U4+OcI9ZFF9XTMSRe0IBDGMbeQ3QR/NhIfenqa4TBgfiTIDmYrf X-Received: by 2002:a05:622a:49:b0:3ef:3361:75d5 with SMTP id y9-20020a05622a004900b003ef336175d5mr190529qtw.11.1685470600656; Tue, 30 May 2023 11:16:40 -0700 (PDT) MIME-Version: 1.0 References: <20230530163546.986188-1-azeemshaikh38@gmail.com> In-Reply-To: <20230530163546.986188-1-azeemshaikh38@gmail.com> From: John Stultz Date: Tue, 30 May 2023 11:16:30 -0700 Message-ID: Subject: Re: [PATCH] clocksource: Replace all non-returning strlcpy with strscpy To: Azeem Shaikh Cc: Thomas Gleixner , linux-hardening@vger.kernel.org, Stephen Boyd , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Tue, May 30, 2023 at 9:35=E2=80=AFAM Azeem Shaikh 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]. > 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#strlcp= y > [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* s= tr) > { > 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; > } Sounds reasonable to me. Acked-by: John Stultz Thanks for submitting this! -john