From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C31FDC001B0 for ; Wed, 9 Aug 2023 15:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231611AbjHIPa3 (ORCPT ); Wed, 9 Aug 2023 11:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232178AbjHIPa1 (ORCPT ); Wed, 9 Aug 2023 11:30:27 -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 2C0EF1FD4; Wed, 9 Aug 2023 08:30:27 -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 B5FBD639F5; Wed, 9 Aug 2023 15:30:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 753E4C433C8; Wed, 9 Aug 2023 15:30:23 +0000 (UTC) Date: Wed, 9 Aug 2023 11:30:21 -0400 From: Steven Rostedt To: Marco Elver Cc: Kees Cook , Andrew Morton , Guenter Roeck , Peter Zijlstra , Mark Rutland , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Nathan Chancellor , Nick Desaulniers , Tom Rix , Miguel Ojeda , Sami Tolvanen , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Dmitry Vyukov , Alexander Potapenko , kasan-dev@googlegroups.com, linux-toolchains@vger.kernel.org Subject: Re: [PATCH v3 3/3] list_debug: Introduce CONFIG_DEBUG_LIST_MINIMAL Message-ID: <20230809113021.63e5ef66@gandalf.local.home> In-Reply-To: References: <20230808102049.465864-1-elver@google.com> <20230808102049.465864-3-elver@google.com> <202308081424.1DC7AA4AE3@keescook> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Wed, 9 Aug 2023 11:57:19 +0200 Marco Elver wrote: > static __always_inline bool __list_add_valid(struct list_head *new, > struct list_head *prev, > struct list_head *next) > { > - return __list_add_valid_or_report(new, prev, next); > + bool ret = true; > + > + if (IS_ENABLED(CONFIG_HARDEN_LIST)) { > + /* > + * With the hardening version, elide checking if next and prev > + * are NULL, since the immediate dereference of them below would > + * result in a fault if NULL. > + * > + * With the reduced set of checks, we can afford to inline the > + * checks, which also gives the compiler a chance to elide some > + * of them completely if they can be proven at compile-time. If > + * one of the pre-conditions does not hold, the slow-path will > + * show a report which pre-condition failed. > + */ > + if (likely(next->prev == prev && prev->next == next && new != prev && new != next)) > + return true; > + ret = false; > + } > + > + ret &= __list_add_valid_or_report(new, prev, next); > + return ret; > } I would actually prefer DEBUG_LIST to select HARDEN_LIST and not the other way around. It logically doesn't make sense that HARDEN_LIST would select DEBUG_LIST. That is, I could by default want HARDEN_LIST always on, but not DEBUG_LIST (because who knows, it may add other features I don't want). But then, I may have stumbled over something and want more info, and enable DEBUG_LIST (while still having HARDEN_LIST) enabled. I think you are looking at this from an implementation perspective and not the normal developer one. This would mean the above function should get enabled by CONFIG_HARDEN_LIST (and CONFIG_DEBUG would select CONFIG_HARDEN) and would look more like: static __always_inline bool __list_add_valid(struct list_head *new, struct list_head *prev, struct list_head *next) { bool ret = true; if (!IS_ENABLED(CONFIG_DEBUG_LIST)) { /* * With the hardening version, elide checking if next and prev * are NULL, since the immediate dereference of them below would * result in a fault if NULL. * * With the reduced set of checks, we can afford to inline the * checks, which also gives the compiler a chance to elide some * of them completely if they can be proven at compile-time. If * one of the pre-conditions does not hold, the slow-path will * show a report which pre-condition failed. */ if (likely(next->prev == prev && prev->next == next && new != prev && new != next)) return true; ret = false; } ret &= __list_add_valid_or_report(new, prev, next); return ret; } That is, if DEBUG_LIST is enabled, we always call the __list_add_valid_or_report(), but if only HARDEN_LIST is enabled, then we do the shortcut. -- Steve