Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp231062pxb; Mon, 13 Sep 2021 17:49:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyruHdmjBRzsH9p3LVdKfU/0PFqGsWo0bv/z59kR7Jag7bU0xBuh3/Rp/hs4jOO1xkSzqPY X-Received: by 2002:aa7:dd4e:: with SMTP id o14mr15842734edw.104.1631580597023; Mon, 13 Sep 2021 17:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631580597; cv=none; d=google.com; s=arc-20160816; b=QsoM110dLN0Qtf6BcjP9ehYgnyTpho4aPC9y4dLSNTY41hpdoKgtuJEQE+ea1XDbFO FLCSBJlrPxHVjPfSJVY5Tv975amSSyS8VV0VcNPy7KfGX0RxP3B7iVJ9N6PRtkMVLmTg +eUQ8l1wMzgZOqCuWfmM8YKM1JxqEHzGKZ7pA0IErwUacVEg9hNfNey6LdqQCpQQZSq4 NVnI7z40H2LKD9LmRBlMXQYsQRfZrk6O5w+nawr9wT6yCmd7NrefD1eOQXaM6Lu4Aszg 1P/AWqXwZ3dBCelJ+wTixQ/lj6QSSv+BPXyf90boFSCkfFcaYj3huhRH5NRlKEgwzW9M Xk7g== 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=kK4t1GfCZjAJ+MwZXVT/5/aigFHECw88ediQCDf2tN0=; b=0n+WjvZMWQYSB624SCZmKGi9ReXo8KyPS037pMPTYW/YncKaC0jYvm90HHcyjUurZe JBgahaigi61CAuIEaL7ijMIC0YbeVIWXX/JgglmRxm57b0D8C96Lg1zWcdjLcvsiSTJ5 4VsSkS9YgR4VyRV0OR6ajsBGUBeiLjzuvLXKGWSTLrQHdgvAEBr/osx1ZnZCpyRhMF2R mIHcjMJsuBf8ubFN80sH0/q75Mc1TFaoOYu9QzerKOU+yJdNwUCapGRrXjkOUtVdL+cY /ChlaaKEBtn0CugXUc7PhnntK8JOKy8UCwd4OfSbojpPA/hwG6q+YDnzo+aNGcmxjNmX pm/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GVc7OI7q; 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 x2si11677877ejy.297.2021.09.13.17.49.33; Mon, 13 Sep 2021 17:49:57 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GVc7OI7q; 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 S1344151AbhIMR7W (ORCPT + 99 others); Mon, 13 Sep 2021 13:59:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:48868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239541AbhIMR7T (ORCPT ); Mon, 13 Sep 2021 13:59:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4789B60F25; Mon, 13 Sep 2021 17:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631555883; bh=wKCgWwoggfMMEuOXBW33VvCRW6LZGGnafN7FiiDq0po=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GVc7OI7qomibj+raAPEjY0UE8y/XsG3CJBeVKxT/5I+pml7HfSZatFAoBHdmO8hMf B4sF/hEfbMZvKo0GdiqrKxq/puFzbu+1iClo7Rim1tTKQyW4lCLGYZiPPs3o8aeLRB 4i776bLcYny/wE3eRkpN79oS/jmeNQpx24V+/hvQ= Date: Mon, 13 Sep 2021 19:58:01 +0200 From: Greg Kroah-Hartman To: Naresh Kamboju Cc: Nathan Chancellor , Nick Desaulniers , Baokun Li , open list , linux-stable , Hulk Robot , Josef Bacik , Jens Axboe , Sasha Levin , clang-built-linux , lkft-triage@lists.linaro.org, llvm@lists.linux.dev Subject: Re: [PATCH 5.14 018/334] nbd: add the check to prevent overflow in __nbd_ioctl() Message-ID: References: <20210913131113.390368911@linuxfoundation.org> <20210913131114.028340332@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 13, 2021 at 09:52:33PM +0530, Naresh Kamboju wrote: > On Mon, 13 Sept 2021 at 19:51, Greg Kroah-Hartman > wrote: > > > > From: Baokun Li > > > > [ Upstream commit fad7cd3310db3099f95dd34312c77740fbc455e5 ] > > > > If user specify a large enough value of NBD blocks option, it may trigger > > signed integer overflow which may lead to nbd->config->bytesize becomes a > > large or small value, zero in particular. > > > > UBSAN: Undefined behaviour in drivers/block/nbd.c:325:31 > > signed integer overflow: > > 1024 * 4611686155866341414 cannot be represented in type 'long long int' > > [...] > > Call trace: > > [...] > > handle_overflow+0x188/0x1dc lib/ubsan.c:192 > > __ubsan_handle_mul_overflow+0x34/0x44 lib/ubsan.c:213 > > nbd_size_set drivers/block/nbd.c:325 [inline] > > __nbd_ioctl drivers/block/nbd.c:1342 [inline] > > nbd_ioctl+0x998/0xa10 drivers/block/nbd.c:1395 > > __blkdev_driver_ioctl block/ioctl.c:311 [inline] > > [...] > > > > Although it is not a big deal, still silence the UBSAN by limit > > the input value. > > > > Reported-by: Hulk Robot > > Signed-off-by: Baokun Li > > Reviewed-by: Josef Bacik > > Link: https://lore.kernel.org/r/20210804021212.990223-1-libaokun1@huawei.com > > [axboe: dropped unlikely()] > > Signed-off-by: Jens Axboe > > Signed-off-by: Sasha Levin > > --- > > drivers/block/nbd.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c > > index 19f5d5a8b16a..acf3f85bf3c7 100644 > > --- a/drivers/block/nbd.c > > +++ b/drivers/block/nbd.c > > @@ -1388,6 +1388,7 @@ 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: > > @@ -1402,8 +1403,9 @@ 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: > > - return nbd_set_size(nbd, arg * config->blksize, > > - config->blksize); > > + if (check_mul_overflow((loff_t)arg, config->blksize, &bytesize)) > > + return -EINVAL; > > + return nbd_set_size(nbd, bytesize, config->blksize); > > case NBD_SET_TIMEOUT: > > nbd_set_cmd_timeout(nbd, arg); > > return 0; > > arm clang-10, clang-11, clang-12 and clang-13 builds failed. > due to this commit on 5.14 and 5.13 on following configs, > - footbridge_defconfig > - mini2440_defconfig > - s3c2410_defconfig > > This was already reported on the mailing list. > > ERROR: modpost: "__mulodi4" [drivers/block/nbd.ko] undefined! #1438 > https://github.com/ClangBuiltLinux/linux/issues/1438 > > [PATCH 00/10] raise minimum GCC version to 5.1 > https://lore.kernel.org/lkml/20210910234047.1019925-1-ndesaulniers@google.com/ > > linux-next: build failure while building Linus' tree > https://lore.kernel.org/all/20210909182525.372ee687@canb.auug.org.au/ > > Full build log, > https://gitlab.com/Linaro/lkft/mirrors/stable/linux-stable-rc/-/jobs/1585407346#L1111 Has anyone submitted a fix for this upstream yet? I can't seem to find one :(