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 X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E3C6C433F5 for ; Tue, 14 Sep 2021 02:13:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21F6E610CE for ; Tue, 14 Sep 2021 02:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236896AbhINCOq (ORCPT ); Mon, 13 Sep 2021 22:14:46 -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