Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3518636rwe; Mon, 29 Aug 2022 13:34:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR7mfwnfK4Gqd7AsPsbm8p+OXEcQNYVoIDGxpkkGPNGRUYSPCf4IKONHoHoKwPC4IEP5b+Oe X-Received: by 2002:a17:902:d510:b0:175:b31:fa9b with SMTP id b16-20020a170902d51000b001750b31fa9bmr1644002plg.73.1661805258310; Mon, 29 Aug 2022 13:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661805258; cv=none; d=google.com; s=arc-20160816; b=P4gJ0G0VRgVcxbcXGzbyPEBZqGWYCabqh3hNuiYYhrKCkewc38EuIOps5xCxz/UrMG cAggx52hD/rUmdUf9uj0uXqdTONm5Uxr9wSIISrpuhCycEV9xpcFpAkWEhVD6oD2uIe3 4Isb1+CR9NgIJner83wYRYXqKt8qtQziQDHKp1Q4vOfYyygeSe/UP9sWmuGiagJK9OwB hTcYM4U/wI1IZQvQObOCrijpyLl1LW/I/YrXbsLL+EkfNbeNzQMIMwOlmrKJDwnwLnbw +8/jFruyl8P6e7s30SBXJrd+ii69GyD9bf0k+6lm7aWgAMgHNt0+tKGVV4HRevcSNcO4 17Ig== 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=1CsC/FWb8WgaluJDmDm40y1bvBnIW2XutzXzMERabjA=; b=k/RH+wq/nEZ3yrtwB5vDi/g3h0RzvrzARvaNZmm6D2Jboo8+tnOQ11zWmVarIRxgvv lp7TWGYCU+gjM7Qberhpt4Gc3W9dJFYAeJaQfu9iiGxtQof/Isp3G3NL8rClgVUYHI8e ZRDUzBthsY+ZNJGzS+eS9v5FdX2+6zUpvn9vBg1BKrgqk+WBIii5hg6k2Wur1lpRLBia oE6z/oog0pbZfTbOS6jt+EbZgg4q6AGtLZixRuVWPAiPUz+UxraVHLjrDLwvNTp0E8vj goyChDkIcOMNX74yu3LNIHivI0U86q6ztzy6mipa0Bx409/SWpJm6OBFI6HFTfjRE77U ru5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VbNLqqeZ; 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 z15-20020a63e54f000000b0041a4118f5f5si272655pgj.109.2022.08.29.13.34.07; Mon, 29 Aug 2022 13:34:18 -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=VbNLqqeZ; 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 S229804AbiH2TbA (ORCPT + 99 others); Mon, 29 Aug 2022 15:31:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiH2Ta6 (ORCPT ); Mon, 29 Aug 2022 15:30:58 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 951E361B3C for ; Mon, 29 Aug 2022 12:30:55 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id y1so7102802plb.2 for ; Mon, 29 Aug 2022 12:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=1CsC/FWb8WgaluJDmDm40y1bvBnIW2XutzXzMERabjA=; b=VbNLqqeZg2KuvsdyYDHVh5IfEHGACO5jS28RmaEKdp/aEsNFKK11/UqlCTrJPEdxt/ uqup/asJB8IzRjRJ4yjBJIuIY8NbLSOSdMAaEWLU09RSS581WMrGhZwr07PmBcxQPR2O 8Tc4/JPGvhGSWFypB/Wn32txLcD9p5xbydeIQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=1CsC/FWb8WgaluJDmDm40y1bvBnIW2XutzXzMERabjA=; b=g6gb1Xs5PXUH9xafFJsPFMWr8GkpOlUprKt2DGjDWmj6Se7Gv8bPTaMclBMz386f6u jRoGaiH3zUF7CtLsLGEI2N0TvRPaoUDVgQuwpybGgtvNFa6XKsGLOrcvXgmMMfPPLJB9 8vkPt19QJepPnl15uP+WCId/dRs0s6UNFtYSWMATo/M8KcL0VlZg8IDhYHkhKPH35mM1 L02eNZBzAIZCcDLOuOJgBaat8uSUfLQjopu3ZxzHqJwfJtj9Qkl3jkUfRmVpTm9hGltM wZarecpGvUq8zffNnN2WJBvCWwew6/Hu+8hsCTpoWhsRyFOnLJzCKthaWkQSWHkiNnqs h5vA== X-Gm-Message-State: ACgBeo2d9hsEWEpo7cEXG3/zNKxowiiqIaV+sZUKDhpLCyko/tD2hqzW uosbRMAzTxRTBo67UH5NhFELmQ== X-Received: by 2002:a17:90b:4a82:b0:1fd:9c58:daff with SMTP id lp2-20020a17090b4a8200b001fd9c58daffmr11716679pjb.48.1661801455123; Mon, 29 Aug 2022 12:30:55 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id p124-20020a622982000000b0052e7f103138sm7644099pfp.38.2022.08.29.12.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 12:30:54 -0700 (PDT) Date: Mon, 29 Aug 2022 12:30:53 -0700 From: Kees Cook To: Bart Van Assche Cc: linux-kernel@vger.kernel.org, Andrew Morton , Arnd Bergmann , Dan Williams , Eric Dumazet , Ingo Molnar , Isabella Basso , "Jason A. Donenfeld" , Josh Poimboeuf , Luc Van Oostenryck , Masami Hiramatsu , Nathan Chancellor , Peter Zijlstra , Rasmus Villemoes , Sander Vanheule , Steven Rostedt , Vlastimil Babka , Yury Norov Subject: Re: [PATCH 2/2] overflow, tracing: Define the is_signed_type() macro once Message-ID: <202208291230.CE410DCBE7@keescook> References: <20220826162116.1050972-1-bvanassche@acm.org> <20220826162116.1050972-3-bvanassche@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220826162116.1050972-3-bvanassche@acm.org> X-Spam-Status: No, score=-2.1 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 Fri, Aug 26, 2022 at 09:21:16AM -0700, Bart Van Assche wrote: > There are two definitions of the is_signed_type() macro: one in > and a second definition in . > > As suggested by Linus Torvalds, move the definition of the > is_signed_type() macro into the header file. Change > the definition of the is_signed_type() macro to make sure that it does > not trigger any sparse warnings with future versions of sparse for > bitwise types. See also: > https://lore.kernel.org/all/CAHk-=whjH6p+qzwUdx5SOVVHjS3WvzJQr6mDUwhEyTf6pJWzaQ@mail.gmail.com/ > https://lore.kernel.org/all/CAHk-=wjQGnVfb4jehFR0XyZikdQvCZouE96xR_nnf5kqaM5qqQ@mail.gmail.com/ > > Cc: Andrew Morton > Cc: Arnd Bergmann > Cc: Dan Williams > Cc: Eric Dumazet > Cc: Ingo Molnar > Cc: Isabella Basso > Cc: "Jason A. Donenfeld" > Cc: Josh Poimboeuf > Cc: Luc Van Oostenryck > Cc: Masami Hiramatsu > Cc: Nathan Chancellor > Cc: Peter Zijlstra > Cc: Rasmus Villemoes > Cc: Sander Vanheule > Cc: Steven Rostedt > Cc: Vlastimil Babka > Cc: Yury Norov > Signed-off-by: Bart Van Assche > --- > include/linux/compiler.h | 6 ++++++ > include/linux/overflow.h | 1 - > include/linux/trace_events.h | 2 -- > 3 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index 01ce94b58b42..7713d7bcdaea 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -239,6 +239,12 @@ static inline void *offset_to_ptr(const int *off) > /* &a[0] degrades to a pointer: a different type from an array */ > #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) > > +/* > + * Whether 'type' is a signed type or an unsigned type. Supports scalar types, > + * bool and also pointer types. > + */ > +#define is_signed_type(type) (((type)(-1)) < (__force type)1) > + > /* > * This is needed in functions which generate the stack canary, see > * arch/x86/kernel/smpboot.c::start_secondary() for an example. > diff --git a/include/linux/overflow.h b/include/linux/overflow.h > index f1221d11f8e5..0eb3b192f07a 100644 > --- a/include/linux/overflow.h > +++ b/include/linux/overflow.h > @@ -30,7 +30,6 @@ > * https://mail-index.netbsd.org/tech-misc/2007/02/05/0000.html - > * credit to Christian Biere. > */ > -#define is_signed_type(type) (((type)(-1)) < (type)1) > #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) > #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) > #define type_min(T) ((T)((T)-type_max(T)-(T)1)) > diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h > index b18759a673c6..8401dec93c15 100644 > --- a/include/linux/trace_events.h > +++ b/include/linux/trace_events.h > @@ -814,8 +814,6 @@ extern int trace_add_event_call(struct trace_event_call *call); > extern int trace_remove_event_call(struct trace_event_call *call); > extern int trace_event_get_offsets(struct trace_event_call *call); > > -#define is_signed_type(type) (((type)(-1)) < (type)1) > - > int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set); > int trace_set_clr_event(const char *system, const char *event, int set); > int trace_array_set_clr_event(struct trace_array *tr, const char *system, Yeah, this looks good. I'll take these as part of the hardening tree since it's touching overflow.h, unless I hear otherwise. :) -- Kees Cook