From patchwork Wed Aug 17 21:42:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9286621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1FC6C60839 for ; Wed, 17 Aug 2016 21:42:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1201B2950D for ; Wed, 17 Aug 2016 21:42:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 067D629512; Wed, 17 Aug 2016 21:42:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 1FD0C2950D for ; Wed, 17 Aug 2016 21:42:45 +0000 (UTC) Received: (qmail 22205 invoked by uid 550); 17 Aug 2016 21:42:35 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: kernel-hardening@lists.openwall.com Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 22146 invoked from network); 17 Aug 2016 21:42:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FjPss7p4uNYv/MR6nXoTXtq00FK+N8kk+w8fYGQQLIk=; b=ocm5bwOqr9uq+2vZURwpIMWqLUiABTPTakeecSoiRFTl+U7SXajCNYcYiTtW7yGnN+ YG1A8QMx+64faAE94E8ae21oGJkOiBW3JWmeVtWwZjaEkL6PYz+zCK+slTjdM+CKjYXV pqSN4de1Z5R8/Jd3ODCr+fEoJ6UDc1KVNVtZM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FjPss7p4uNYv/MR6nXoTXtq00FK+N8kk+w8fYGQQLIk=; b=LtQjHYWV8KF5VreyAc4U84ro5ERGifXDxhXx5JRC6vZ+1dkwRXr7xCWTyeJ4RC4UDw uqGd/7wkenX/cAJFK5+ZGJsSZEbGPl7PPaJlP5UKac2cCvHTDrZJ6eUxUe7U01QE8uqJ Rtm7+6FhxxH6me6j+pDPIszaTkAuY2uA/D7T3oocSPDk5MgMCPYMWvYs7rqEHb7vo8HZ ANM/5xd3oWUm+OUh0pGlRC+yfq+AlsIM9TmIYGKhXF+1ZPfoMrgfnbs7Wggxiq6yz3vL mRQ1q09IbIDZ8GUB0JrTe8Vxd9jrEGDW1iLJry25rWayPy//TcLpind4h7nRmJjaOwfy YnFw== X-Gm-Message-State: AEkooutcEA+DlbR2gOpoLRWcWqsjFpuHINWgWZpDfl8D6n5OY751LEixJ2Gtgpy6NwyFtcfI X-Received: by 10.98.79.27 with SMTP id d27mr78095001pfb.127.1471470142900; Wed, 17 Aug 2016 14:42:22 -0700 (PDT) From: Kees Cook To: "Paul E . McKenney" Cc: Kees Cook , Laura Abbott , Steven Rostedt , Daniel Micay , Joe Perches , Stephen Boyd , Syed Rameez Mustafa , Arnd Bergmann , Greg Kroah-Hartman , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , "Aneesh Kumar K.V" , "Kirill A. Shutemov" , Michael Ellerman , Andrew Morton , Dan Williams , Jan Kara , Thomas Gleixner , Josef Bacik , Ingo Molnar , Tejun Heo , Andrey Ryabinin , Nikolay Aleksandrov , Dmitry Vyukov , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Wed, 17 Aug 2016 14:42:09 -0700 Message-Id: <1471470132-29499-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471470132-29499-1-git-send-email-keescook@chromium.org> References: <1471470132-29499-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH v3 2/5] rculist: Consolidate DEBUG_LIST for list_add_rcu() X-Virus-Scanned: ClamAV using ClamSMTP Consolidates the debug checking for list_add_rcu() into the new single debug function. Notably, this fixes the sanity check that was added in commit 17a801f4bfeb ("list_debug: WARN for adding something already in the list"). Before, it wasn't being checked for RCU lists. Signed-off-by: Kees Cook --- include/linux/rculist.h | 8 +++----- lib/list_debug.c | 19 ------------------- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/include/linux/rculist.h b/include/linux/rculist.h index 8beb98dcf14f..4f7a9561b8c4 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h @@ -45,19 +45,17 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list) * This is only for internal list manipulation where we know * the prev/next entries already! */ -#ifndef CONFIG_DEBUG_LIST static inline void __list_add_rcu(struct list_head *new, struct list_head *prev, struct list_head *next) { + if (!__list_add_valid(new, prev, next)) + return; + new->next = next; new->prev = prev; rcu_assign_pointer(list_next_rcu(prev), new); next->prev = new; } -#else -void __list_add_rcu(struct list_head *new, - struct list_head *prev, struct list_head *next); -#endif /** * list_add_rcu - add a new entry to rcu-protected list diff --git a/lib/list_debug.c b/lib/list_debug.c index 149dd57b583b..d0b89b9d0736 100644 --- a/lib/list_debug.c +++ b/lib/list_debug.c @@ -77,22 +77,3 @@ void list_del(struct list_head *entry) entry->prev = LIST_POISON2; } EXPORT_SYMBOL(list_del); - -/* - * RCU variants. - */ -void __list_add_rcu(struct list_head *new, - struct list_head *prev, struct list_head *next) -{ - WARN(next->prev != prev, - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n", - prev, next->prev, next); - WARN(prev->next != next, - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n", - next, prev->next, prev); - new->next = next; - new->prev = prev; - rcu_assign_pointer(list_next_rcu(prev), new); - next->prev = new; -} -EXPORT_SYMBOL(__list_add_rcu);