Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4113176iob; Tue, 17 May 2022 14:23:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOpg85ha0Qi2fjDDE1vJU9aaQAXB3eLoOjUnw+OHPag7luCXJUFVy0nse+bCUqyaeZl7uZ X-Received: by 2002:a17:902:c7cd:b0:161:8b6f:73c3 with SMTP id r13-20020a170902c7cd00b001618b6f73c3mr9313970pla.156.1652822626524; Tue, 17 May 2022 14:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652822626; cv=none; d=google.com; s=arc-20160816; b=hg64wAEMP9KA7mp+U6bG2uvPxGywsE1Y2QGCidXHvr1iX/mV7efjP2h34NBYSxouxG o+O9TVk6p8CBZ5eECGuqTLFXDxbEBMyNmY/XRF2FUwGRuEPyZRKEhaXp5uEHmDF7OTQx HJTxommyrN3PGG8tUqchqCrsbDZ0WoG8658/JQ6Oi5XIueKfL2y0T4/WY/zDTfx6VjmC QsGEJEswmwkfZadWErlEoEckqapBejAW3tChA1/pjzd+ZBKZStzDX6TegkRUJcXbrzfF HejqN673kVNzmYI8IKTAWYUSZL1WNvPNZYvx+4zGVxtcClnRPs4MbHhGuAUDO5k8Sw6T aW1w== 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=JWJH0H3VnL630PpxKgPoS9Ozluel4tO19edpwjN9dAY=; b=lsc/OKZcgb5FKarfvP0jnmUAPbq3kH8KnDhNZV+R/Dy4ShWs1/Sa4hv1YUl0HTO+oJ A8Ti2olodNxIvNtsl+c8mJOFy5FChX93mCpxDUktVRFfjqPCr+xlPIQx9dkD2RjU/Fyt zV0qPkAD6FAaAIa0PeGU999E6XXHBolaLu107nmuMIKgmtVaeIWMQZCoEngbJoEFIeCf WY3483TOJiA1P38Q/yWUE6GCu/QoXiLV5+1h8thcHbGXlPMYyi4bcEBbEaHdj34/Q59E 9BY1wAMW+GcNnndMaxFsuggwNfPwRuFpsROe94k9/s6aikeXRhepQKMc0lc+q0eYQNMM 1zpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UY58ZLPS; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nv5-20020a17090b1b4500b001cb7551c772si3941513pjb.163.2022.05.17.14.23.35; Tue, 17 May 2022 14:23:46 -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=@chromium.org header.s=google header.b=UY58ZLPS; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351236AbiEQVPr (ORCPT + 99 others); Tue, 17 May 2022 17:15:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238483AbiEQVPp (ORCPT ); Tue, 17 May 2022 17:15:45 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27F882AD5 for ; Tue, 17 May 2022 14:15:44 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id i8so4488262plr.13 for ; Tue, 17 May 2022 14:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=JWJH0H3VnL630PpxKgPoS9Ozluel4tO19edpwjN9dAY=; b=UY58ZLPSUEWH1oW7m8vE1PZXb1XF9W65pNy+7zoChQg79UoRE+M07cnON1DfeFsiNR UTWXwYpV9VNT7S+u/LK2EYC4HNZQcm1aZBmLsIAwiBq8kBAwi/JRkBVnsTQdqQmygL+N 9eJAm5HiiqC1SLddngx11AH+JvWWyw6IFRufI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JWJH0H3VnL630PpxKgPoS9Ozluel4tO19edpwjN9dAY=; b=aX/Mpi2Z5q0s8zzAmsfklctymlWnH3h/CbFaonAAVSHRvpLkfnNhEeOYKu6OIAw90O YdbSB1Cbyeyi8Hc5vNNp72/3CqpcCvuEaHM8Tdpvsg7a9zNQjs6mI1RwFdkl6WBPSgPp w//AwVNaTke+wDTZDFk2U8Fqn08JQjfx49+rK0ltzRTQ16ShmJmxBBPxgI1gjUfTkPqm ioZ8V2UhmIMV8k/c6JRb1ldHs0bUnLv6YfFnItmnlKWF4Mkxv6DtpYTuuNqoP92ktT9/ 46tvDvS9V8B3AxNhNfCnkDhcTOHO5USZx7dihFM/pIjQivcYXLZlIqKyZnLNTW6breY2 8Ekw== X-Gm-Message-State: AOAM532l1ywkguc3uVIdH3G+dUNZfS7h4eI6WJR0khjwDXOPMBOnHpgl 7NSmJJzxH8Zuwtlku9DeD4bh1A== X-Received: by 2002:a17:902:7886:b0:15f:4cc6:3196 with SMTP id q6-20020a170902788600b0015f4cc63196mr23676659pll.127.1652822143657; Tue, 17 May 2022 14:15:43 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id mq7-20020a17090b380700b001cd4989ff5esm52794pjb.37.2022.05.17.14.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 14:15:43 -0700 (PDT) Date: Tue, 17 May 2022 14:15:41 -0700 From: Kees Cook To: Rasmus Villemoes Cc: Yury Norov , Christophe de Dinechin , Andy Shevchenko , Andrew Morton , Zhen Lei , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] bitmap: Fix return values to be unsigned Message-ID: <202205171414.D21437E7@keescook> References: <20220517035411.31144-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 17, 2022 at 08:49:38AM +0200, Rasmus Villemoes wrote: > On 17/05/2022 05.54, Kees Cook wrote: > > Both nodemask and bitmap routines had mixed return values that provided > > potentially signed results that could never happen. This was leading to > > the compiler getting confusing about the range of possible return values > > (it was thinking things could be negative where they could not be). Fix > > all the nodemask and bitmap routines that should be returning unsigned > > (or bool) values. Silences GCC 12 warnings: > > So, for the bitmap functions themselves, makes sense, and then also for > the nodemask functions which are merely wrappers around the bitmap > functions (or wrappers around wrappers ...). But see below. Cool. I think I should split this into two patches. > > > > > #define first_node(src) __first_node(&(src)) > > -static inline int __first_node(const nodemask_t *srcp) > > +static inline unsigned int __first_node(const nodemask_t *srcp) > > { > > - return min_t(int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES)); > > + return min_t(unsigned int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES)); > > } > > Unrelated to the type change, but what's that min() doing there in the > first place? Doesn't find_first_bit() already return the nbits argument > if no "first bit" exists (i.e., the bitmap is empty)? > > > #define next_node(n, src) __next_node((n), &(src)) > > -static inline int __next_node(int n, const nodemask_t *srcp) > > +static inline unsigned int __next_node(int n, const nodemask_t *srcp) > > { > > - return min_t(int,MAX_NUMNODES,find_next_bit(srcp->bits, MAX_NUMNODES, n+1)); > > + return min_t(unsigned int, MAX_NUMNODES, find_next_bit(srcp->bits, MAX_NUMNODES, n+1)); > > } > > Same here and a few more places. > > It seems to go all the way back to pre-git. Hm. Could be cleaned up > separately I guess. Yeah, all I find as a hint is: /* FIXME: better would be to fix all architectures to never return > MAX_NUMNODES, then the silly min_ts could be dropped. */ which also predates git history. > > > > > #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1) > > -extern int node_random(const nodemask_t *maskp); > > +extern unsigned int node_random(const nodemask_t *maskp); > > So this one I'm not convinced about. It has a documented return value of > NUMA_NO_NODE aka -1 if the mask is empty. And since it's not a wrapper > around a corresponding bitmap_random() (which would presumably, did it > exist, use the "return nbits if empty" convention), there's no > compelling reason to make its return type unsigned. Agreed; I'll drop this change. Thanks! -- Kees Cook