Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1981265pxb; Mon, 13 Sep 2021 09:24:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3lahPdiCU8eFVn2pzWCHbfDWMaPRFXjNkNL8iIztuqnD+fUj7exFe15Dx2Y0U72lixQ0t X-Received: by 2002:a05:6e02:1250:: with SMTP id j16mr8414606ilq.215.1631550252998; Mon, 13 Sep 2021 09:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631550252; cv=none; d=google.com; s=arc-20160816; b=BD5VZPXW4rEDUrMyunpe6k8B+Dl8yjgvV+fTqDyELJLJcAppUUVwWJVXW9eFEkWSp/ jdfSFt6556yvsmYjdz9177Uzc9L+zaMFZHhQRsINtlGkN/lprrIAnCQd47FhQ3mjrpjM t6LxkGiar5HFcuRr+6aeh2iWdLoOLoDUTnsTJfDpAA0O79tB7y56mxYyN6FwCY3/aH5A di0lpm18NA6FZj/IkFzNeKnBefAILRYVBtL6pe+cc3pKojCI3P3NUcsKxh3jOFSQ8rJn VP/cQ/Fqu4dmF9bSXM86iUgq+DyzMGMPmhrZfoWsNzIbdCQs8Ish/qIi3OKwDDUfk6Fj R3sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4/ivNU19vgx8JM95ZcxudD+bsQ3V+RD7J/J7pfkup6o=; b=1LtlNKAQfUZ0SMk6vgiJwUKcH6LkYNhTqoFURaNTYsk/sEtkYpdjGI4CPCmrTeyq9U MBaL4NRcWHLx2tF4sPonl2l7ycmA5IeJEiWZWC+4t94XydcZn85GGB+veJbCtkhpz0R1 gj07bwmxBjo2hot2rb0rvxLg9e/+mg1W4Lym3rVOh7g1oImihqhWX3w26qn8AsjCE+Vy dxZAkRMBFZKKXt1yA+44qowmuqIGN6SKRduo6tlgw2R2AglnfWButI4+DEl5KkgCo3c8 dow3Oa53k8n0DWs7njoic/QnXJeAy0aOQn2htGOa/4+F1Q+6pNDqNAc6BHZuDIQnrCj1 Tk8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a1kK2KQf; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si8135199ilk.152.2021.09.13.09.23.59; Mon, 13 Sep 2021 09:24:12 -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=@linaro.org header.s=google header.b=a1kK2KQf; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232959AbhIMQYG (ORCPT + 99 others); Mon, 13 Sep 2021 12:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236804AbhIMQYB (ORCPT ); Mon, 13 Sep 2021 12:24:01 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 668BEC061760 for ; Mon, 13 Sep 2021 09:22:45 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id bd1so14760022oib.5 for ; Mon, 13 Sep 2021 09:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4/ivNU19vgx8JM95ZcxudD+bsQ3V+RD7J/J7pfkup6o=; b=a1kK2KQfiezpSLJ2ORWWym+07BdpzPI+E6gijxIsvsZQamk6qGrPWV/3o5PSSAsuOr 3A+MsrvZXXq9ScwMKCl3Jz2clIb3a9oB5bXugBk+kOyvRJegjV57DmSz9AEz+Aiqslf4 f2GQ5sqhzgkHTI6wJ91yabyDkmYOQg8mXmjBD+qTZMOjHWiJBQ8Gd8OudErVWiWm8LHb lk10kSue7CYfSDDIbp9h7Exl94gah9Qbuk/PN03BVfiJen1pSrRstSprN2S/H6L53YyI OLZf5bwowa9GyrvGQXd4LoQ77XiiZutJzeceFf6JdIjod/XQ4gvqgZZ8HO4sZR7oIDRm RMNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4/ivNU19vgx8JM95ZcxudD+bsQ3V+RD7J/J7pfkup6o=; b=8RPdksK99rsaPALZacw8jKuxrWGK5sjIk3C7W9A+paHRrs7YTqjYsAatHKK6j5Q+PF Qy+3BcK6ynmh0Nm0g2mVkjEq2mZfjHdGX5Z8ABHXIOon7K3Q132etm+QrPzy9hqoFXzO efkZBMnd4qxhFcMtdceJu9z9T1IFVqY1KkNMU5gZWwM486uyTy1P1MB8zs5sT+i8egVM jLF604euMgrARWwn/QSO5wTql7Tr23RZHxJpKPqKvVBuV7lqjONvCPYObduWxFiZ9/Fe +QIe2EB09QtnIfA2OjxiLwbJpSyOrzaT+/PhRyGND8zKLIDsI7S4NPcZZdpM7bdRCE5t wbow== X-Gm-Message-State: AOAM5324tyU228fv3Ke4ljh5x+gwi+JEEdBGcQ6sSrPpezMXX6ssaKE8 2wGicJC706H//LVj3IhiKmCahLEOrCAxLdkru+ZC3A== X-Received: by 2002:a05:6808:118:: with SMTP id b24mr8614615oie.0.1631550164556; Mon, 13 Sep 2021 09:22:44 -0700 (PDT) MIME-Version: 1.0 References: <20210913131113.390368911@linuxfoundation.org> <20210913131114.028340332@linuxfoundation.org> In-Reply-To: <20210913131114.028340332@linuxfoundation.org> From: Naresh Kamboju Date: Mon, 13 Sep 2021 21:52:33 +0530 Message-ID: Subject: Re: [PATCH 5.14 018/334] nbd: add the check to prevent overflow in __nbd_ioctl() To: Greg Kroah-Hartman , Nathan Chancellor , Nick Desaulniers , Baokun Li Cc: open list , linux-stable , Hulk Robot , Josef Bacik , Jens Axboe , Sasha Levin , clang-built-linux , lkft-triage@lists.linaro.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- Linaro LKFT https://lkft.linaro.org