Message ID | 20230703113737.694995-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp474014vqx; Mon, 3 Jul 2023 05:14:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7D9u5fbLvt/jgJnFfL8fuTM8zCfvv3NVlXf3LQLNUIP7yqa95meDkT6fHFPTAflaCOfXul X-Received: by 2002:a6b:b282:0:b0:780:d65c:d78f with SMTP id b124-20020a6bb282000000b00780d65cd78fmr10088175iof.2.1688386471635; Mon, 03 Jul 2023 05:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688386471; cv=none; d=google.com; s=arc-20160816; b=i8aVr7TdKmPKV4UnoFMIKQFKVpy8D08fnXvCT+P2Ht/yRBt85zCpHjUc7SjH3pzB2u YZW1Bx2evYsDvMeEq92CUxmxf9EDZpOus+YsdvA3BbvdXR4zHY5OqSwwfs2gDGbkoStF XiD7GuIPBtFrc0/ptwjDvhMULDvnIGtZKI1GvU97GZCH1z2l9uerIRGe0+gW1cPVwAci GdFRylMs9yrWy2VHL34WsNHQy359UqWglqDhaGOkA8p+TowLOT2ECgCFQKIqXxUO0VMq CzGtbAm1UgxiQSvGVB6fmS/Yhm4kZkdr9cX6ydmVZr6gXsyCQlnFRngeNnbKzZLIAgoO pmWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=M6hBJAkwInWwXiWguUXB5FNTUSQPF9lEX6qRmGzny4I=; fh=fLcCYCiujSOCF8vx2gWcdxAthqJkfQNNrRgY4s7VYZY=; b=JBBgHAlORPh4tsF0IfAlsIVouQ4+6rszXi8Ar95QDElLQY1/NkbFiVN5tLalrfLbMv PXiZPpGc7fL9zNdWXk3s6lgIkKbnz8pvnvQ/uWubDFqtx+ABzK6Op1owYqhkhMXImBdG awdxnte4PLJWMa7rierzjPbPR4oNrKcMtuB/ZQ/qMSB4tHJGK3n0IMnYNmw6Q7Q2eq8H WvGcgvz9r1u57L2zfwa0EIwh6TFI3h3DJb2Fkpo3ibP64vfZJdE3XLksa/PmhELk4+zp oURoPOomlqpTGDJzj7EpBTVYctWjKOcKg8jNzqCfrOKyf+fEmNrULkVOCa4zJ6WQV/3M bUJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BUJp2I4t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j62-20020a638041000000b00557221f00c7si19901138pgd.335.2023.07.03.05.14.18; Mon, 03 Jul 2023 05:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BUJp2I4t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231131AbjGCLiJ (ORCPT <rfc822;ivan.orlov0322@gmail.com> + 99 others); Mon, 3 Jul 2023 07:38:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbjGCLhy (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 3 Jul 2023 07:37:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67140198; Mon, 3 Jul 2023 04:37:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EE59760F00; Mon, 3 Jul 2023 11:37:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00269C433C9; Mon, 3 Jul 2023 11:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688384264; bh=NWdm4COWp2k09VYLKv3/EMMJkaiYec6oWrtpHhnAdio=; h=From:To:Cc:Subject:Date:From; b=BUJp2I4tfvNJnQyBQ7mRS4r9bhjY6iDaZatDtPvGUGRSMTW+yTIuvFgIodu6nfukJ Ir3sfcG1YlLLR9YZXB6YIKumcnsyEd1orp1XlNfFS9pcIYFUF7hYuu/PLv1gquQ+MX eUbjrWhcdg89M2+/8hr9u8aM5D7jmRhg49yjetMcM2Yp8lbDHDfIxnBf8Xxqiul2LG IQeQdjKFGFzUHJTaDSlprBM7iQ2e3D5C84bDauoUdzk5V7ZQxGBB9sGJMT7vjXYjv7 rLfln/mxaLdx0zGVrdVVW4hfbm7SV9AgnrElV5CGJ266xfcDdY/+71CCzEb+AUQUCR G3sPgBRvhHiig== From: Arnd Bergmann <arnd@kernel.org> To: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org>, Trond Myklebust <trond.myklebust@hammerspace.com>, Anna Schumaker <anna@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de>, Neil Brown <neilb@suse.de>, Olga Kornievskaia <kolga@netapp.com>, Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, Dan Carpenter <error27@gmail.com>, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] sunrpc: avoid constant-out-of-range warning with clang Date: Mon, 3 Jul 2023 13:37:22 +0200 Message-Id: <20230703113737.694995-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770401533023799990?= X-GMAIL-MSGID: =?utf-8?q?1770401533023799990?= |
Series |
sunrpc: avoid constant-out-of-range warning with clang
|
|
Commit Message
Arnd Bergmann
July 3, 2023, 11:37 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de> The overflow check in xdr_stream_decode_uint32_array() was added for 32-bit systems, but on 64-bit builds it causes a build warning when building with clang and W=1: In file included from init/do_mounts.c:22: include/linux/sunrpc/xdr.h:778:10: error: result of comparison of constant 4611686018427387903 with expression of type '__u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare] 778 | if (len > SIZE_MAX / sizeof(*p)) Shut up the warning with a type cast. Fixes: 23a9dbbe0faf1 ("NFSD: prevent integer overflow on 32 bit systems") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- include/linux/sunrpc/xdr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Mon, Jul 03, 2023 at 01:37:22PM +0200, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The overflow check in xdr_stream_decode_uint32_array() was added for > 32-bit systems, but on 64-bit builds it causes a build warning when > building with clang and W=1: > > In file included from init/do_mounts.c:22: > include/linux/sunrpc/xdr.h:778:10: error: result of comparison of constant 4611686018427387903 with expression of type '__u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare] > 778 | if (len > SIZE_MAX / sizeof(*p)) > > Shut up the warning with a type cast. > > Fixes: 23a9dbbe0faf1 ("NFSD: prevent integer overflow on 32 bit systems") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > include/linux/sunrpc/xdr.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h > index f89ec4b5ea169..6736121ee6a03 100644 > --- a/include/linux/sunrpc/xdr.h > +++ b/include/linux/sunrpc/xdr.h > @@ -775,7 +775,7 @@ xdr_stream_decode_uint32_array(struct xdr_stream *xdr, > > if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0)) > return -EBADMSG; > - if (len > SIZE_MAX / sizeof(*p)) > + if ((size_t)len > SIZE_MAX / sizeof(*p)) > return -EBADMSG; > p = xdr_inline_decode(xdr, len * sizeof(*p)); I sent a patch for this last week that takes a different approach. https://lore.kernel.org/all/2390fdc8-13fa-4456-ab67-44f0744db412@moroto.mountain/ I probably should have used a Fixes tag just for informational purposes. regards, dan carpenter
On Mon, Jul 3, 2023 at 5:42 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > On Mon, Jul 03, 2023 at 01:37:22PM +0200, Arnd Bergmann wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > > > The overflow check in xdr_stream_decode_uint32_array() was added for > > 32-bit systems, but on 64-bit builds it causes a build warning when > > building with clang and W=1: > > > > In file included from init/do_mounts.c:22: > > include/linux/sunrpc/xdr.h:778:10: error: result of comparison of constant 4611686018427387903 with expression of type '__u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare] > > 778 | if (len > SIZE_MAX / sizeof(*p)) > > > > Shut up the warning with a type cast. > > > > Fixes: 23a9dbbe0faf1 ("NFSD: prevent integer overflow on 32 bit systems") > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > > --- > > include/linux/sunrpc/xdr.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h > > index f89ec4b5ea169..6736121ee6a03 100644 > > --- a/include/linux/sunrpc/xdr.h > > +++ b/include/linux/sunrpc/xdr.h > > @@ -775,7 +775,7 @@ xdr_stream_decode_uint32_array(struct xdr_stream *xdr, > > > > if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0)) > > return -EBADMSG; > > - if (len > SIZE_MAX / sizeof(*p)) > > + if ((size_t)len > SIZE_MAX / sizeof(*p)) > > return -EBADMSG; > > p = xdr_inline_decode(xdr, len * sizeof(*p)); > > I sent a patch for this last week that takes a different approach. > > https://lore.kernel.org/all/2390fdc8-13fa-4456-ab67-44f0744db412@moroto.mountain/ > > I probably should have used a Fixes tag just for informational purposes. I have a slight preference for retaining the existing error handling here, but am happy to have 2 fixes in hand rather than 0; thank you both for your time looking at this. Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> > > regards, > dan carpenter >
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index f89ec4b5ea169..6736121ee6a03 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -775,7 +775,7 @@ xdr_stream_decode_uint32_array(struct xdr_stream *xdr, if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0)) return -EBADMSG; - if (len > SIZE_MAX / sizeof(*p)) + if ((size_t)len > SIZE_MAX / sizeof(*p)) return -EBADMSG; p = xdr_inline_decode(xdr, len * sizeof(*p)); if (unlikely(!p))