Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp8308972rwd; Tue, 20 Jun 2023 13:15:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51DfTjYG1twqZEXt9tBUv3B5JVKF7G/IlYKhL7HwrLcVuOTZSOuckMejeia3FbZ/3p6AUV X-Received: by 2002:a05:6a00:300c:b0:66a:3b01:2347 with SMTP id ay12-20020a056a00300c00b0066a3b012347mr245633pfb.2.1687292132350; Tue, 20 Jun 2023 13:15:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687292132; cv=none; d=google.com; s=arc-20160816; b=Z+hEPeTQ1IVGGPfGwtRGwA1d9Q3OC5uZf09xasiKwyc6x+EBgRWF314lyLPwlDGt20 /hqDzz97ouaUY3e4ygLOFUTbpVCWWSulRl7gjcIsquocSjPaFF2c7xDN63YU146s2TKe xrzocZWVIyhMwuAxoWpu1LRsYDXzLlGlzrcT7MWRoaKGU861TVG9e2gyBia8GN299qYf DJx0X1UnBOXESdZdHBP5akBB1H2fdmuYK1egmKaM2LKRVDCnKxR983BzRswmeY0n+nTW WIVKdjoOPlnI4DaR3XE+Oz+n44tTbNSyUbOyqBQXXPVrbHMYt7VhAWdYvNUTEv61w66V kY4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7mZw/sH51+Uar7fU1OzH0F4S7kdt3jyea8NkuZO28Fc=; b=VwMmS49dzGBXnWNUWilxUkMY+oCVVBMj4aGZJ6mPmrTTKuwlZJ5S8h1Ck4edJ8vpc8 +I6hy8ULNkVzuIb1fImsLYv09NCa+NhVTHsSseoOL7MyiE1kYA68eZEeDg83kpF5pxLF mIjTBYb6gFX5weTAKvfgYcjayfasI41K3cdoYu/4g2pfR8t6O/CgF/5AOtlb9B2tXs7J bu1byFKuCEDioWfKVn6VHx6hQRBIIA3O9tOFgpZgFS1snr7DQjO/o3oFFSbOwE6c2J7B qHO8cyBYBoMLeCHiXVlZ/55czCfHh6iTuci2y7oF4IPjgooFlsN5tbEWMaTkcpM/lJyC hRaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="ACC8bD/i"; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w129-20020a627b87000000b00652dbdb97d5si2312335pfc.356.2023.06.20.13.15.14; Tue, 20 Jun 2023 13:15:32 -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=@chromium.org header.s=google header.b="ACC8bD/i"; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbjFTUMN (ORCPT + 99 others); Tue, 20 Jun 2023 16:12:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbjFTUML (ORCPT ); Tue, 20 Jun 2023 16:12:11 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 794A1DC for ; Tue, 20 Jun 2023 13:12:10 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-666ecb21f86so3982182b3a.3 for ; Tue, 20 Jun 2023 13:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687291930; x=1689883930; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7mZw/sH51+Uar7fU1OzH0F4S7kdt3jyea8NkuZO28Fc=; b=ACC8bD/ipJx7pFzTlJOQa4nyrUG0GCpU0e6G0XEoriY8gcAwE7ALynO0pU1O0kgraM CkjuTcns0qiLbR847qdCQpfBleJWKbiMFilCJpuB4SKzHaW73B6qWlc5+edSEeylFROW zHY2Wg+k+MboEax1G49d1ghl0fO8gG1GE+MFA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687291930; x=1689883930; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7mZw/sH51+Uar7fU1OzH0F4S7kdt3jyea8NkuZO28Fc=; b=X/L32EqyVKk+GYQLX9gOi6MFmm6taUnlB9b+la6BOYK7HFg3fD0Ul/zxvwEJYg/4HT cHcNrIKVfn2LHVfK84Aki0qRqFHbqP7fSSJ4SKybEjsirnbWQOU9XczdqOQTBpDpb3fc 0t/FJ+sZ1yD0Rv7+QzA7VMAvmYkjQ7vALm+xyrdqrkqWF2Ah0i9v8fQRIVur7PKxE7tj ZJxcPh9WK2QMf30WjOTkZpbTDdzoR8Wf3ba7hP1QYlxt/HVdJduFdfZWKGjcsYVRcJUO lw0YTRZSQHLflSyU42FSEriI4jm2mpY0lCK5Mnu09MKco8tR36YdRuQQ1uQqP4Yemgt3 Eu8g== X-Gm-Message-State: AC+VfDzuKUnLpWTMJqvBx+sQBhwN7R5ApUZ/vhP7cIUXlkDmzZx0waLQ uqoP8LeX9Xj50Y+QLMGmUzXc6g== X-Received: by 2002:a05:6a21:6daa:b0:105:12ab:878f with SMTP id wl42-20020a056a216daa00b0010512ab878fmr16307871pzb.56.1687291930016; Tue, 20 Jun 2023 13:12:10 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id r23-20020a634417000000b005143448896csm1761874pga.58.2023.06.20.13.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 13:12:09 -0700 (PDT) Date: Tue, 20 Jun 2023 13:12:08 -0700 From: Kees Cook To: Azeem Shaikh Cc: Herbert Xu , "David S. Miller" , Eric Biggers , linux-hardening@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] crypto: Replace strlcpy with strscpy Message-ID: <202306201311.862B05981F@keescook> References: <20230620200832.3379741-1-azeemshaikh38@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230620200832.3379741-1-azeemshaikh38@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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#strlcpy > [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 -- Kees Cook