Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34749528rwd; Sun, 9 Jul 2023 19:46:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlG43yMb90eGgYWgwlrHKVe7ktZu57cGq4idjv64G16j/KCKSFb2V1R770Tj92kf2Q3ab7Qg X-Received: by 2002:a05:6000:11c2:b0:30a:f103:1f55 with SMTP id i2-20020a05600011c200b0030af1031f55mr9924244wrx.0.1688957216017; Sun, 09 Jul 2023 19:46:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688957216; cv=none; d=google.com; s=arc-20160816; b=eO5ZBb1r4Pd3r8kZo4kFstK3Kog6W9UgpeQfXXTUidXZXk5Khl9tMaMy4vC0w7pJQp V2FH+bW8xmMMXaA07EKRIfOJLXlk8EEiCCtZXrw2SuDAYZaUzVv/nGIAvEC4cC50jZ3f Faz+oMrVUOkg00INJWeEyKR8hJwJOx/gyCGH2PYXbh3KfVs2yvUATOQIhywFdmopqnhx Q7BRSAjGPFNuBFtOukAIlGiadEtsuCzXqnHLgofJ4U6QRzVlcNanw5Hki4OAZ/f66lMP Pc3hkDa8b5ZsxShyyTdbj+mzV2jGa3w977DiAmyJgPR+ut0zCjf41YsEKuWWtCQgVZQn 1fZQ== 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=W3XEg4q7KHiIFxw+vZ9TCJt73U1Opkr0tChPrvQjUrw=; fh=gfb+ME03gs/sbntiyUlKuyrL3JOzvR8oGf6DvK5tvmw=; b=CqO/A6uNRLRKgLXRcqH3z7N126dB+7x154d9/I5qitFZw3TB70MUNEXPRb5pNTzPAc 7jFbnmmohblSRf8VgBU5kOp+Y0VFutAh3zyNZpOY++gJbIBXcSECZ3uxtxqPEapgL7Nt VtGhWDywBbotVC9n4o27I/SQF0TJvY4J+iF//DBCjXy6/Sz+izqqwTa55VvDCxJ1tYG8 bpxpd6QfkoOJpfp/tKqRb8zZnCs2aHanfCiU9nU7OryZPyFLa2QGjJ3HK0plfjwP8x6n Tr8fKa9pPz03x6SKnG1aHBm0k02lzG04BFS88kXEES0dRrJHH/uapFPbrkcPFabjzlah nd5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=piUG3eNN; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 p6-20020a056402074600b0051e0310f5b2si8603177edy.642.2023.07.09.19.46.25; Sun, 09 Jul 2023 19:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=piUG3eNN; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S229983AbjGJCg5 (ORCPT + 99 others); Sun, 9 Jul 2023 22:36:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjGJCg4 (ORCPT ); Sun, 9 Jul 2023 22:36:56 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1FC0E0; Sun, 9 Jul 2023 19:36:55 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-c5f98fc4237so3773307276.2; Sun, 09 Jul 2023 19:36:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688956615; x=1691548615; 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=W3XEg4q7KHiIFxw+vZ9TCJt73U1Opkr0tChPrvQjUrw=; b=piUG3eNNngUZ5OivMBd56VnDb7ZVpVgDcp5zmA3oWTAjtGTSEVzmBrFnmNJ7f75aKc GFieFnE58F29a7GgRRkVRTsEuczvcBvg7MegkvgjSXbWtZxGq5b+2XpssKUEbfgJ9NhA tOcQ+j99cxSR0PYV6tHQ9wZ2Ja8k/q8vuHK+myhKSKWZLVbOnqPVmR+ahvyHSaOhjRKm IwMGPV2HzLNHsISosPCgAnYb1mUTgIxyWAspy/3A1331Xv/VzwFTRdXndsbeNMq+1Ov6 OUW/kw9+QCeq3teFHV+EoYMgokRoHYPjJU3ornzKXdM9Q7v+LKFee2r2060CJDi7ib8C EpIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688956615; x=1691548615; 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=W3XEg4q7KHiIFxw+vZ9TCJt73U1Opkr0tChPrvQjUrw=; b=DUjldnsaAqpwn5B+HnQL6BgFJGo0srBJESFgKvHZFbODEzcL8ywcCBEAndLxwauJW7 T90HveAdTruUyGqk57Wnc2mphxfSWCV4VOOREaOqSDZ9E+o//yT5S0FYUpjtAFoFB+Tn 8SxlzeqBpbpnBR1eey/Ce+amESv/owNCE2g0k3/8OUgr5ishlfRdjnEdcVtJMpf6hpLW Pxyn8CxAFVcaOw4ROqaSITgH5JczIL9EnpQOswWD985C12Oc533bR7D8lEdgvMWJEEWF C8MI19akGqaNEPHo6ONImJ/rsHu58jyCiwfdSM7+c8CE5higkDp4csPNzYPyjHcBWi3a QUTQ== X-Gm-Message-State: ABy/qLYRttZBWsGnTyuoUmbeh+qELyR/0pND6dH0U7E0JyhftqmQBLoL yZDyZQjxDmTmVPJ/x4zQvo4JaM7QGW4rseSsKeY= X-Received: by 2002:a05:6902:87:b0:c5d:d6cd:fade with SMTP id h7-20020a056902008700b00c5dd6cdfademr5535414ybs.50.1688956614808; Sun, 09 Jul 2023 19:36:54 -0700 (PDT) MIME-Version: 1.0 References: <20230620200832.3379741-1-azeemshaikh38@gmail.com> <202306201311.862B05981F@keescook> In-Reply-To: <202306201311.862B05981F@keescook> From: Azeem Shaikh Date: Sun, 9 Jul 2023 22:36:44 -0400 Message-ID: Subject: Re: [PATCH v2] crypto: Replace strlcpy with strscpy To: Kees Cook Cc: Herbert Xu , "David S. Miller" , Eric Biggers , linux-hardening@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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-crypto@vger.kernel.org On Tue, Jun 20, 2023 at 4:12=E2=80=AFPM Kees Cook w= rote: > > On Tue, Jun 20, 2023 at 08:08:32PM +0000, 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(). > > > > Direct replacement is safe here since return value of -errno > > is used to check for truncation instead of sizeof(dest). > > > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strl= cpy > > [2] https://github.com/KSPP/linux/issues/89 > > > > Signed-off-by: Azeem Shaikh > > Thanks for fixing up the variable type. (And thank you Eric for catching > the signedness problem!) > > Reviewed-by: Kees Cook > Friendly ping on this.