Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10296658rwd; Wed, 21 Jun 2023 20:30:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6vpE+2WccepEqI6eWsCyvU0MKIbrJi1C7fByH5QRQDqNsjG6LLHRUEfl+faqyvk5YN7xwu X-Received: by 2002:a05:620a:948d:b0:763:9d33:a93f with SMTP id sn13-20020a05620a948d00b007639d33a93fmr10357989qkn.30.1687404651583; Wed, 21 Jun 2023 20:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687404651; cv=none; d=google.com; s=arc-20160816; b=VmcFXmWzln+r7RaYuDZDzA6Cl80i5m/a5fG4r0Ar4ut76SxD8f5su4w+wgLkvscAiV ubDh2+9tBNqBlrh2inYqFBG/y8Xjiex3aeXz08ZoFCjpkth73u2i6wzj5huvT+wPQPlt rY1tZyR5Hc+A1qVJqkAlf5D+04cMs7nU0zkXkbQjIatBB9S0SIhDc/rnsAwvO5zz+n+1 J5TXxROW7QLlQNgyZLcILQWg/rlZTMUSIs9Q1AcJiIst73PPnJjWNh3DkxOL5Lzn8o0W Czu0HPaGpE2qS0DEy1GVIXHAAso9ei4hTbV9b8ps8uI5UXBS11kPwWyRVDI3Qa8x9WSe XhxQ== 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=bgLDqCZpojqPASYki3iZZPdkOuhPJ8cSSL0f5T0zXIA=; b=sobvkYai3MjIVXRaYIG032MoAN6EjHdUDx7Xm5L3s3/v+ZEtBl0xWkyE9MkzlPWE3F U45jeiyxVxjJNAywsZlVfZr5aC4PtCbNQex3BWH0jRCHwKaxVu+/9trwgglpf+aC+u4m t58mqGiPLX7QEgrEnRbcv5A7rR3xO9YyFtKAHRO/tiveTYnDKGE2SfCopByv9Sotb1wq HOKjYB6UHnmZeuDobYD927Bk7LP2lRTsicpkNAH9H730j0+/m6i4mPhenV49zvZ8ma3m Qp1Y7e1V24nLj8q8G37gBTvDi1YU+gidbjG4Jp0xnU9dYHzwM8y1XJl4Rdlk5UwXUMt9 EwDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NaDa2kmt; 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=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 q144-20020a632a96000000b0054fe7540eeesi5266411pgq.886.2023.06.21.20.30.39; Wed, 21 Jun 2023 20:30:51 -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=@chromium.org header.s=google header.b=NaDa2kmt; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229732AbjFVDKz (ORCPT + 99 others); Wed, 21 Jun 2023 23:10:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbjFVDKw (ORCPT ); Wed, 21 Jun 2023 23:10:52 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E38D1981 for ; Wed, 21 Jun 2023 20:10:51 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-517bdc9e81dso2706988a12.1 for ; Wed, 21 Jun 2023 20:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687403450; x=1689995450; 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=bgLDqCZpojqPASYki3iZZPdkOuhPJ8cSSL0f5T0zXIA=; b=NaDa2kmtGYXFAl5nKLBIfYEThEldVX1HQN1gWRxGOcR/tb2DdTg4FasoBgOfrzSQGX Wrd+fdQeOHg+rZkvxGKK2aYG+Cm4brn8actk4tnZaqCuLMXQg7JApNCdgBDwlQFoLFY/ 9UxhiL6JHCQT1rHWSM+mJUOqFCLcK2RrCaoaY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687403450; x=1689995450; 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=bgLDqCZpojqPASYki3iZZPdkOuhPJ8cSSL0f5T0zXIA=; b=dN7z4PiVc5mpZpaC1T0WnTE4mFY1RvcAAglFdRzFGN08giEL6Zt8XtH4YzRj6BY9Sm 9mBSNVguN3uSy5ZeIstwZlGo2WUrqUl1qcz5WiPy2oZ2Ms6HQUffaK5adi0xQiwqFYX8 7Q5xteU0HEuGq9ArEO5kGaL7UCQhp557U9LHTwUah94t49Rs3ru6+kKNeWwNLh++BYDD bZw6fKBsdls+7HOcX4MKqUNq2xtmzF2GboBI565aPsJtUlskDZ9iRRFVgIa5jO2wbJZq GK70mzRY1QHMm/R7oXfFa2JGUHL3gtj+/lb9YhuQ2w6ePWML25FgcYl9aYczlHmEO5+p I8Tg== X-Gm-Message-State: AC+VfDzUK9utm5dgDbaZvTF29ckoCpCT9iAVbj4vWvPA6g6adcmY8yjO yvuTU/xTSE/kMVxTPE9DKrEbPQ== X-Received: by 2002:a05:6a20:160d:b0:111:c8a6:88ca with SMTP id l13-20020a056a20160d00b00111c8a688camr17825068pzj.58.1687403450536; Wed, 21 Jun 2023 20:10:50 -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 u9-20020a17090341c900b001a2104d706fsm4125573ple.225.2023.06.21.20.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 20:10:49 -0700 (PDT) Date: Wed, 21 Jun 2023 20:10:48 -0700 From: Kees Cook To: Azeem Shaikh Cc: Greg Kroah-Hartman , Valentina Manea , Shuah Khan , Shuah Khan , linux-hardening@vger.kernel.org, Hongren Zheng , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] usbip: usbip_host: Replace strlcpy with strscpy Message-ID: <202306212010.E6CBCE23E@keescook> References: <20230615180504.401169-1-azeemshaikh38@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230615180504.401169-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 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 Thu, Jun 15, 2023 at 06:05:04PM +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 Reviewed-by: Kees Cook -- Kees Cook