Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp954096pxb; Wed, 29 Sep 2021 13:23:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygA4DmHpmmk6PqPDMO5j5fwPwNV09R7oJ36v/au7uPCB/+m5r4qzSF+qCuAU6mCyjhVtdg X-Received: by 2002:a17:902:9687:b0:13d:b848:479d with SMTP id n7-20020a170902968700b0013db848479dmr1672023plp.59.1632946991865; Wed, 29 Sep 2021 13:23:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632946991; cv=none; d=google.com; s=arc-20160816; b=ffyyWrUlPgt2AbHJKFQnyd3X0zgCJsMVbCYAME+dKZSWYe1Md85U3z7rIT/YnnmCQJ uJAkSbJCKonG7IEK0gRw7isH0in6s0VjHu2ubhu6aPolIhyJwaji1BOqGfZppkhEdx19 pCEz4ldBxv6RD+I9g6KzEs/7fn2609fMup5O+1G+gp88QXYzsBMIvDjGjDNrcOItEp7r b0Z9Pf/EHxBfvwqX9NreSC5CnMYq4LV0w1hhSv3xgjxozvyUR0hxP6geYtCpId2OCh+V uMduAnYp+thVBmDaTGzknl8jwLP/thVKpDRd/Ad0QP9C2NUuk6hzrhL2RcbDtf+UDevK BpHg== 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=02EXaRR/LNadeGaGEAJYu9eu7Tm3d0AkQIYMMcAXP4c=; b=I+xRGZNl+kNIJwD9ObSJ05OWLlVySJY1B0wOgzrQ9C2WrHRaIfy91g3g2ze2hFdQy7 XZ14ju3OEQ64di4INH3xcgnhIrsd/1nT13Lhh0UBCdHNlwhStTTaOuOktil41qZOymte rFJDeUhDqv7aERY8fIvwF6A6DENp0kdXAsWpw4Qce+FEpcaXjJPSdKG7GXUSodgxIJ3n sQfnw/ZKilwLCfwrJ/6aVqPxQbUTVfetRYxjM+XV70yIwEHUYY9EgtPH/UW8sQwXQy2s CgiG5vSv5p0HOJFqc9c0Et29lhf6UszI2kFSaJWGfXhepaOSex9txm35ywUQJ2NAbC1k cW5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20210112.gappssmtp.com header.s=20210112 header.b="LE4/GyFb"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m18si1327733plx.127.2021.09.29.13.22.56; Wed, 29 Sep 2021 13:23:11 -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=@toxicpanda-com.20210112.gappssmtp.com header.s=20210112 header.b="LE4/GyFb"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346586AbhI2UUy (ORCPT + 99 others); Wed, 29 Sep 2021 16:20:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346369AbhI2UUx (ORCPT ); Wed, 29 Sep 2021 16:20:53 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62967C061764 for ; Wed, 29 Sep 2021 13:19:12 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id b16so3533139qtt.7 for ; Wed, 29 Sep 2021 13:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=02EXaRR/LNadeGaGEAJYu9eu7Tm3d0AkQIYMMcAXP4c=; b=LE4/GyFbg6PDYrFzMabU3wOkVWt1bHu/gEgjJL5r//rlKzDS9g6ZiNQZLgEqE5952C dhL0UwiqvNKYDPPQwubbwnqD9mpLnpOEj3bv8j2jO1T9MAE3sZYwQ6v4I0zIsPKYyZ4O rdmxyzL/WT5dtPbI02l1h0ZBCIiueWXex102uRrAV0withKV6ROlvuDYxJP2cXQYBS2P MiqX0CMENIKK+QG5J5hg8kAfOm4AOlfDXgGFEFmsQPmHc89hK9HHWbd0922OIa0ky0DK +koVjJRzBZVdI1lt+yaJcdYnUZs9aEE637ZhmjvS56wbP/NlDDSnzSlUs5LBT01p5N49 lXxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=02EXaRR/LNadeGaGEAJYu9eu7Tm3d0AkQIYMMcAXP4c=; b=5CwXTP+JJTGyBcyiOxlaRjbBl62O8d8Ypj0huRONxqovazE4XBXaITnTfUD2dPGhvH JLrI/GU3Bx3LIrjWF5h/49jYME0gpyVtjCJqr+0IUYvsiN81E/720Oy7KsoStnXGZkdD NPpOnk70NnWt9Pn3hPuODQ+wK9m0SM3mjHNvAvPS9Bx2oZ2r5ha7Pacp2meF4J4hfte7 cP+deKZSlMVWl1N7oWgz3LRgnQf+L7MiarRqYBAyF9bIhzCTjgeoVQIRx++KrWtKPDfk jjntAiwPBpocbklC1XgPLAZ5auRVak5ug2WHNrBlqr508IdFiRjtewa1xWHtZxvxSjLB MwVg== X-Gm-Message-State: AOAM533n9PaLxKteuBzxAR5Mr2lCm1+0BQfuDWn6nMok4LKGi3t3xu9+ +o4gKHCfjCQ2rfI7gLMZGVH5oA== X-Received: by 2002:ac8:4243:: with SMTP id r3mr2223327qtm.187.1632946751266; Wed, 29 Sep 2021 13:19:11 -0700 (PDT) Received: from [192.168.1.45] (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id z10sm485338qtv.6.2021.09.29.13.19.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Sep 2021 13:19:10 -0700 (PDT) Subject: Re: [PATCH] nbd: use shifts rather than multiplies To: Nick Desaulniers Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Rasmus Villemoes , Naresh Kamboju , Nathan Chancellor , Stephen Rothwell , Kees Cook , Linus Torvalds , Pavel Machek , Jens Axboe , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev References: <20210920232533.4092046-1-ndesaulniers@google.com> From: Josef Bacik Message-ID: <079a17e7-6cf1-7632-bf12-1df0edf4f93a@toxicpanda.com> Date: Wed, 29 Sep 2021 16:19:09 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20210920232533.4092046-1-ndesaulniers@google.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 9/20/21 7:25 PM, Nick Desaulniers wrote: > commit fad7cd3310db ("nbd: add the check to prevent overflow in > __nbd_ioctl()") raised an issue from the fallback helpers added in > commit f0907827a8a9 ("compiler.h: enable builtin overflow checkers and > add fallback code") > > ERROR: modpost: "__divdi3" [drivers/block/nbd.ko] undefined! > > As Stephen Rothwell notes: > The added check_mul_overflow() call is being passed 64 bit values. > COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW is not set for this build (see > include/linux/overflow.h). > > Specifically, the helpers for checking whether the results of a > multiplication overflowed (__unsigned_mul_overflow, > __signed_add_overflow) use the division operator when > !COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW. This is problematic for 64b > operands on 32b hosts. > > This was fixed upstream by > commit 76ae847497bc ("Documentation: raise minimum supported version of > GCC to 5.1") > which is not suitable to be backported to stable. > > Further, __builtin_mul_overflow() would emit a libcall to a > compiler-rt-only symbol when compiling with clang < 14 for 32b targets. > > ld.lld: error: undefined symbol: __mulodi4 > > In order to keep stable buildable with GCC 4.9 and clang < 14, modify > struct nbd_config to instead track the number of bits of the block size; > reconstructing the block size using runtime checked shifts that are not > problematic for those compilers and in a ways that can be backported to > stable. > > In nbd_set_size, we do validate that the value of blksize must be a > power of two (POT) and is in the range of [512, PAGE_SIZE] (both > inclusive). > > This does modify the debugfs interface. > > Cc: stable@vger.kernel.org > Cc: Arnd Bergmann > Cc: Rasmus Villemoes > Link: https://github.com/ClangBuiltLinux/linux/issues/1438 > Link: https://lore.kernel.org/all/20210909182525.372ee687@canb.auug.org.au/ > Link: https://lore.kernel.org/stable/CAHk-=whiQBofgis_rkniz8GBP9wZtSZdcDEffgSLO62BUGV3gg@mail.gmail.com/ > Reported-by: Naresh Kamboju > Reported-by: Nathan Chancellor > Reported-by: Stephen Rothwell > Suggested-by: Kees Cook > Suggested-by: Linus Torvalds > Suggested-by: Pavel Machek > Signed-off-by: Nick Desaulniers Reviewed-by: Josef Bacik Thanks, Josef