Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp278711pxb; Mon, 13 Sep 2021 19:14:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2qf+PFfqTrFhBdxja7AaT4ogD3K1c63m2jjP64QF7eiHZqFY3C7IFUzSSRls5an6ublwe X-Received: by 2002:a92:cb43:: with SMTP id f3mr5737234ilq.261.1631585662273; Mon, 13 Sep 2021 19:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631585662; cv=none; d=google.com; s=arc-20160816; b=zUEQYYbaE4v6rHx/XX4UPRjmNqizeDSLiHnc5x8i/LV8PFL/+llAxC9Z3y7jjaZuDb Ngqkz33Im0uuRzvHLNk+eiBSCVr98y1ULa82yZHNGRSTqB3efcLR8fBuAu/ntkF0RlEV y7TXlISZzgfkAxBtxTMYJnz9hjYHhpivz1f98TjOInPu3AOSBC3fDSy760/8s2B6ES8Y R7MS++FsiIA14BDiII3m1bgoq6WVdE8NN9OPuuorUt57rdSYotKad4QkHYmr0VqsnYc6 tice063ennUG+Mnaqe2Qb1kYi9CxnRaDH2NPZjQSYofKRAbKHXbbbwG7hqqphuBrPeES F1fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=KMZkTeVa7n/lOkdPK4Jyx3syhOuUmTb/viMMWvQ2YA0=; b=dX2oJIV0xJfCgRqFiBoR3cWQ5RkUApq7Ebe0uANb0fijNRu4M4TJ0vwdzvVNWi1Rgm NMd5MGLWdooi3cQKS4CCmLMRXMVP2YZghzSM9KR282RZhGpXGkCJBJACTZIDbce/wjJL yeU/LZBqvvOB0S3I8b62gtCOgI54uSsvlNHKuusilp0aoiRsExw/mscFDUdV8MB6Cgpq lV+FolgBtOJhY+kaP6Liv8cvfA8hwJtnsxB56dAyvDUDEfhfy+0guXgDx8Z3zliMC0WF Zvp6F1Mdmttz6n1g6/UVsKWH9dDUAtkzeu3BZISGeLH3z8jrt0lgwCmGMACtf1O5Adbt gLvA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t6si5745995ilj.70.2021.09.13.19.14.11; Mon, 13 Sep 2021 19:14:22 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236650AbhINCOp (ORCPT + 99 others); Mon, 13 Sep 2021 22:14:45 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:15408 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231953AbhINCOn (ORCPT ); Mon, 13 Sep 2021 22:14:43 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H7mxW5LDqzR5fC; Tue, 14 Sep 2021 10:09:19 +0800 (CST) Received: from dggpeml500020.china.huawei.com (7.185.36.88) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 14 Sep 2021 10:13:25 +0800 Received: from [10.174.177.174] (10.174.177.174) by dggpeml500020.china.huawei.com (7.185.36.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 14 Sep 2021 10:13:24 +0800 Subject: Re: [PATCH 5.14 018/334] nbd: add the check to prevent overflow in __nbd_ioctl() To: Nick Desaulniers , Linus Torvalds CC: Arnd Bergmann , Sedat Dilek , "Greg Kroah-Hartman" , Naresh Kamboju , Nathan Chancellor , open list , linux-stable , Hulk Robot , Josef Bacik , Jens Axboe , Sasha Levin , clang-built-linux , , , Kees Cook References: <20210913131113.390368911@linuxfoundation.org> From: "libaokun (A)" Message-ID: Date: Tue, 14 Sep 2021 10:13:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.174] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500020.china.huawei.com (7.185.36.88) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/9/14 7:23, Nick Desaulniers 写道: > On Mon, Sep 13, 2021 at 4:00 PM Linus Torvalds > wrote: >> On Mon, Sep 13, 2021 at 2:15 PM Nick Desaulniers >> wrote: >>> Sorry wrong diff: >> Well, this second diff was seriously whitespace-damaged and hard to >> read, but while it seems to be the same number of lines, it sure looks >> a lot more readable in this format. >> >> Except I think that >> >> default: dividend / divisor); >> >> should really have parentheses around both of those macro arguments. >> >> That's a preexisting problem, but it should be fixed while at it. > Ok, I'll send a revised v2 based on _Generic; Rasmus can help review > when he's awake. > >> I'm also not sure why that (again, preexisting) BUILD_BUG_ON_MSG() >> only checks the size of the dividend, not the divisor. Very strange. >> But probably not worth worrying about. > I sent a not-yet-applied diff of my not-yet-applied diff. I was > playing with this last week, and IIRC we had divisors that were less > than 32b being promoted to int. But I'll test it some more. How about deleting the check_mul_overflow in the __nbd_ioctl as follows? diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 5170a630778d..f404e0540476 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1393,7 +1393,6 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,                        unsigned int cmd, unsigned long arg)  {         struct nbd_config *config = nbd->config; -       loff_t bytesize;         switch (cmd) {         case NBD_DISCONNECT: @@ -1408,9 +1407,10 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,         case NBD_SET_SIZE:                 return nbd_set_size(nbd, arg, config->blksize);         case NBD_SET_SIZE_BLOCKS: -               if (check_mul_overflow((loff_t)arg, config->blksize, &bytesize)) +               if (arg && (LLONG_MAX / arg <= config->blksize))                         return -EINVAL; -               return nbd_set_size(nbd, bytesize, config->blksize); +               return nbd_set_size(nbd, arg * config->blksize, +                                   config->blksize);         case NBD_SET_TIMEOUT:                 nbd_set_cmd_timeout(nbd, arg);                 return 0; -- 2.31.1 -- With Best Regards, Baokun Li