Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1686705pxb; Mon, 22 Feb 2021 08:24:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqJwgT407F16ANyJFt3/tA6XjBOi+1v7TTncRs+JcfO8C424lky4hS9HNm5ia8sW45PPet X-Received: by 2002:a17:906:4045:: with SMTP id y5mr21945493ejj.529.1614011071042; Mon, 22 Feb 2021 08:24:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614011071; cv=none; d=google.com; s=arc-20160816; b=uJTbEokJgAyR3TFY1/+CXipZjd8WoVoR6QE7cJItTOiU5HnDW66/oCSr4ySjs6MujY eT/2xjkRcU7IxGs4rVGh6oRFfd0AQvAbPpXp0Kegnonm5QQKB+srdf/6lZ2ocaf/kOqW 7mokfB111i9ZKoXmUFWTWES828rLQyEzDR2e+XUhXBVl9D16TJcmPkpUHJxPwFZpNdiv Wj4cCrueA237HeXGeVZxxfa4XSodpj+Nn3PnlQv1sQ3fQ5W5ZBj8/qMm+ArCTkS4mKHt PyP5masSEJoO6uVZzq+zH7DfQBYuolt8lcsSh+8o0mYUkpznUCzV+pN7wQFuoxNpx/Aq gzSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=O2UdjypR4W3iDVOy5hnKP5de6BTPFEvlQ6oGQr/tzUY=; b=Av0FNaj+dDwekAYsDm1o1KsQUHGIbn/0U74RlYdjXVOPa/CBEVRi8h+TWCar3NIXSk WrGKQr9H38qgwIw3H2Gi0q5TJpubtegPjH2e7YzzMpLguLHDdSE1HSONFOkjbVl8O87N cVlP05q4DYKUBZ8MlxRW/HfQuzwXZr8lph499BudS62lfbiK8CchLTJCXTJHajhzz37u xxTJVmd7qIlRJ9j8MDem2Al4QiK1N6ZoLBJFj9lzXyRB9WWKR62hMcMUg1k9Q4D2cF/W kmyt23wjZZoo6zVWYlpmUIJhmFMjglapBcFC8k/hMvAUYlsJQwLXGBJj7R2dnIx0vck6 s9ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=QWYr4qA6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w8si1899270ejf.46.2021.02.22.08.24.08; Mon, 22 Feb 2021 08:24:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=QWYr4qA6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231598AbhBVQXE (ORCPT + 99 others); Mon, 22 Feb 2021 11:23:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbhBVQWd (ORCPT ); Mon, 22 Feb 2021 11:22:33 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D01BFC061574 for ; Mon, 22 Feb 2021 08:21:51 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id a16so11306419ilq.5 for ; Mon, 22 Feb 2021 08:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=O2UdjypR4W3iDVOy5hnKP5de6BTPFEvlQ6oGQr/tzUY=; b=QWYr4qA6Wc1K2uzDRbRDKEFJU9VggdyiFbE9noSMExFmpSB/WSH/g2hR2wobF0KpKU aVmWFkaH9gj8GcMoYdDsRvYawy/kizivt/PojhfqMjCVxWyJwyMAmuZjBr0OPFcPerai XoppCFZUi/lHoq1JIO0Y7Bw+vx/Vb9gdiubmc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=O2UdjypR4W3iDVOy5hnKP5de6BTPFEvlQ6oGQr/tzUY=; b=PeajbLeWSOlQEAKKWHRQ5glscIppgF/kjKPoYtTFo1KoWyWEHin/jOzfEOq6zVvVM9 OemLpSGdQmmymYcL5Ixh4vhkJM9GIhPpqruPfXZ265Y3W5FTeVUzroy4LLzLtAOfIIpg uBDUxtUwIaYLDRB/zj+piUaxO8C/0yDbr+Bd9Rn3h63o8ZE3d9K19GxtoIpPVlmc5VNC 3KYe9PuRJfTo/hK7A1VwOGiV8Ey1mkzQQgXMvOVMtjoL0+0fAXQrRgqi34Ygm79asRaH 1Gj6r3ke1bB4l72MNvWCdyRvCHUKrU1HJeQ+C7m2JTkcKLwCMCDXcarHczholRoV7AaD u1QQ== X-Gm-Message-State: AOAM532iiw0oaU+laWpFXw2aoD0GamgPGLIXsqOYrrZoBxDllyVLngl7 OkjiSH2bYCpoH3ykrYPMyGLMgg== X-Received: by 2002:a92:1312:: with SMTP id 18mr15099286ilt.92.1614010911339; Mon, 22 Feb 2021 08:21:51 -0800 (PST) Received: from [192.168.1.112] (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id b16sm5383378ilq.49.2021.02.22.08.21.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Feb 2021 08:21:51 -0800 (PST) Subject: Re: [PATCH 19/20] usbip: usbip_host: Manual replacement of the deprecated strlcpy() with return values To: Romain Perier , Kees Cook , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman , Valentina Manea , Shuah Khan Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Shuah Khan References: <20210222151231.22572-1-romain.perier@gmail.com> <20210222151231.22572-20-romain.perier@gmail.com> From: Shuah Khan Message-ID: <0323dcb2-726c-7ea2-8e8b-dba81090b571@linuxfoundation.org> Date: Mon, 22 Feb 2021 09:21:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210222151231.22572-20-romain.perier@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/22/21 8:12 AM, Romain Perier wrote: > The strlcpy() reads the entire source buffer first, it is dangerous if > the source buffer lenght is unbounded or possibility non NULL-terminated. > It can lead to linear read overflows, crashes, etc... > > As recommended in the deprecated interfaces [1], it should be replaced > by strscpy. > > This commit replaces all calls to strlcpy that handle the return values > by the corresponding strscpy calls with new handling of the return > values (as it is quite different between the two functions). > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy > > Signed-off-by: Romain Perier > --- > drivers/usb/usbip/stub_main.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c > index 77a5b3f8736a..5bc2c09c0d10 100644 > --- a/drivers/usb/usbip/stub_main.c > +++ b/drivers/usb/usbip/stub_main.c > @@ -167,15 +167,15 @@ static ssize_t match_busid_show(struct device_driver *drv, char *buf) > static ssize_t match_busid_store(struct device_driver *dev, const char *buf, > size_t count) > { > - int len; > + ssize_t len; > char busid[BUSID_SIZE]; > > if (count < 5) > return -EINVAL; > > /* busid needs to include \0 termination */ > - len = strlcpy(busid, buf + 4, BUSID_SIZE); > - if (sizeof(busid) <= len) > + len = strscpy(busid, buf + 4, BUSID_SIZE); > + if (len == -E2BIG) > return -EINVAL; > > if (!strncmp(buf, "add ", 4)) { > Looks good to me. Thank you. Acked-by: Shuah Khan thanks, -- Shuah