From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98802EB64D8 for ; Tue, 20 Jun 2023 20:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbjFTUMO (ORCPT ); Tue, 20 Jun 2023 16:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbjFTUML (ORCPT ); Tue, 20 Jun 2023 16:12:11 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B9571A2 for ; Tue, 20 Jun 2023 13:12:10 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6686708c986so3387901b3a.0 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=WkO9Qdzd/BVQizH0+lChlYBJPJg8Qcz+bBmNtB7XA9nT/KLqczLYsvIbZ/Rt7x/05a ER/RVu4tGCCYEPasmTlwv+yt450zjYP+neCW10fdHNhHD/BMylDJGka8v+DhyOFDu+q9 JfY02SrYDnHcuGOjnZOnW5zbD574hsTRB2Ai2AQrc9IwdK17j8R9b8f/rXiNZL5/xCYO I9T/KiDGcRK/I6CY9rroLCR1lXNY3ZfpK3oqxXlrjIKGxIrksFitKSE9L05L3ohROMcZ 7cFDUQcCpm9i54efXjeiuCaUXXgTSv4syFsqlVZ29IVRLJfvSCOUAL9I9mLKff1z74SL WKKw== X-Gm-Message-State: AC+VfDzliOEVxXG+YX5UulOeIqD6N8vXTqwqZXhSGVRzDQhPF5owJ3Ir Q5JjBWxcxl2gYRdK6UHNeVXWqA== X-Google-Smtp-Source: ACHHUZ476FchPEseFt3P2/D+fre3+HimYul2bkAmS8gzNZ1hQn6cmMersQMwS8bCAUAN42ovupcufw== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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