From patchwork Wed Aug 17 00:20:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9285013 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 7AEE660574 for ; Wed, 17 Aug 2016 00:20:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BD86287A6 for ; Wed, 17 Aug 2016 00:20:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E809288A1; Wed, 17 Aug 2016 00:20:56 +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 8AD5A287A6 for ; Wed, 17 Aug 2016 00:20:55 +0000 (UTC) Received: (qmail 31781 invoked by uid 550); 17 Aug 2016 00:20:45 -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 30715 invoked from network); 17 Aug 2016 00:20:44 -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=AqXK40mB4d8CUz9KRi4ITuZGjJnwcT4uHkuj54mmwmQwhsVWJX+A13eF3ubeSY2+bE 36eeAlv43iz5IeojaaejnzaSa1JqNnBFy7kGbosO3jZE05e6Quwb0TSLLUVCQQTTrHwp v0DKzbzlIeXaZO1NkKKmMhWaaJO/YQC4SpVx0= 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=P/3rJS/QgUz6ATN/I60WL9UQGAAzp0qjqYyaWA4KhZWHEewXX1qe0QupXN3Bq6//db KkxNAQJeOz1YP+TXaTaigUa+6Keq78vylgHbiANQZoFpriYXAmpRCQe9B0iafHYkppjx 2HEIceHmbvWe2odbqdevBiprdicPA0dwFKB5RLitwtF1eA19pirC8JLCKiHVEMortfJL nNiTb2UQqNB2t7NejzShNVVKydvhmggVJdWmPXBgs2m1avKJRpZPVvcXgZMyghA5Ed7E Iv6/189Slzp6VnE+EnHGq1QXlWlVGJze2A5gEzY/+PnI7wZEvTp6IK/fNwvZS5Q0zCE0 9iDA== X-Gm-Message-State: AEkoouvG8xk2GVuyrDgqQFgtvluN7BsbzSCRrZY1V3TqvVKekHZrdWpbGtDVA4/WeMhZUJTh X-Received: by 10.98.149.131 with SMTP id c3mr69898739pfk.73.1471393232736; Tue, 16 Aug 2016 17:20:32 -0700 (PDT) From: Kees Cook To: "Paul E . McKenney" Cc: Kees Cook , Laura Abbott , Steven Rostedt , Stephen Boyd , Daniel Micay , Joe Perches , Arnd Bergmann , Greg Kroah-Hartman , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , "Aneesh Kumar K.V" , "Kirill A. Shutemov" , Michael Ellerman , Dan Williams , Andrew Morton , Ingo Molnar , Thomas Gleixner , Josef Bacik , Andrey Ryabinin , Tejun Heo , Nikolay Aleksandrov , Dmitry Vyukov , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Tue, 16 Aug 2016 17:20:26 -0700 Message-Id: <1471393229-27182-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471393229-27182-1-git-send-email-keescook@chromium.org> References: <1471393229-27182-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH v2 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);