From patchwork Wed Mar 29 18:15:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9652193 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 EF396602C8 for ; Wed, 29 Mar 2017 18:17:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8BF827165 for ; Wed, 29 Mar 2017 18:17:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD583284EF; Wed, 29 Mar 2017 18:17:11 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DB40327165 for ; Wed, 29 Mar 2017 18:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=LnoSKhje+XJN7HdYBPMycybRQ20fXSXYWcC/fQZvm9s=; b=evmO1F9rMFnPpFxv2OdcJgkN0t Zv7rdpUYeLCBFvdz0CO5YhyuKL7u6k1tUJIaPDL/Uk9Vst12/92yaTzjQ9Fk/Uz5BfiGhS7E1dJqo ROTyKfcI9XKP1zmKRdx1G5qBLvrlr/elw3ZUBL1ai+8Lg+oGj5L28b2AGQWMftpGkMMnnL1RQbn3P /X5Qs3zx8CtSViSK18oOvRxorbzqnGl6sJfWIjRPnDcu5HUVZSJvoowbpjjOv8/0d+0VOTrMjbYhj jUphCEN/CqMF2USagpLg//wyAQiDaRrbfBR/qX0OERFh+3k+CfDeSs4E1bBUEGxxUlKR79oV7eJSW x2iLGtgA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctI9d-0005Zg-Vs; Wed, 29 Mar 2017 18:17:10 +0000 Received: from mail-pg0-x229.google.com ([2607:f8b0:400e:c05::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctI9D-00058I-9T for linux-arm-kernel@lists.infradead.org; Wed, 29 Mar 2017 18:16:45 +0000 Received: by mail-pg0-x229.google.com with SMTP id x125so14691076pgb.0 for ; Wed, 29 Mar 2017 11:16:23 -0700 (PDT) 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=920E8IiQPXj4gcwdOJFBtnnGgv+Igp1RPVnUZ3PFZ5k=; b=FYz837HFvLqgi8fxwWdBSoJHjIZvqFssIrhp6a9k+VhnoiapLkvYEJeUq0yyENmZf2 vxsB6Fgm+VPyByxmJ31BWTsyPpoZ3AvnHdxRXegUmD6cFLanwdfGOaHOz/fhvpoC64T/ YXFvzj4IHgEzkQ6h23TXbrr1ExbtGwXnqHq/Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=920E8IiQPXj4gcwdOJFBtnnGgv+Igp1RPVnUZ3PFZ5k=; b=WblyvoanSYXkZh8VezFvMrt66qNgnjWvwT2AWHKv+AOQpDyKUHrefB7aKLBq3WiFkX /n0+hAJrQKC38HVyRv/TCygSs0ksg4ns/3VtT9kHj5YxSYbljWpS085ML770C/2xB/Oa wMJQtkZBb5WdRvB0Do8nVe/wjoag/s5sVcM0ON1M82IL08Wz3khu3AnlneYFFbNHgC3Y GdinHxJCO7O4qtam9tB2Qd2vbgqJ/LL+HS15w3ccIQ1y6ZdFSGyZcB7mzELJfYlZo0ee dkeK0azwU0L8yAGFVj1Ao+gE1oPiRHo8CPQHQoKA/uHFgw1T9WxZnlN2dtv2akJV6S/C +/1g== X-Gm-Message-State: AFeK/H0TLCH5kJRZPteAaeLs9+mhq6av+boqYLIWP2uIkGCbtqVlBsrctMVRq1orKMx7QooH X-Received: by 10.99.120.206 with SMTP id t197mr1863676pgc.21.1490811383399; Wed, 29 Mar 2017 11:16:23 -0700 (PDT) Received: from www.outflux.net ([2002:ada4:7085:0:b458:dd9:213f:65d]) by smtp.gmail.com with ESMTPSA id e70sm14829785pfl.105.2017.03.29.11.16.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2017 11:16:22 -0700 (PDT) From: Kees Cook To: kernel-hardening@lists.openwall.com Subject: [RFC v2][PATCH 03/11] net: switch sock_diag handlers to rare_write() Date: Wed, 29 Mar 2017 11:15:55 -0700 Message-Id: <1490811363-93944-4-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490811363-93944-1-git-send-email-keescook@chromium.org> References: <1490811363-93944-1-git-send-email-keescook@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170329_111643_446114_CE3ECC8B X-CRM114-Status: GOOD ( 11.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Hoeun Ryu , Kees Cook , x86@kernel.org, Russell King , linux-kernel@vger.kernel.org, Emese Revfy , Andy Lutomirski , PaX Team , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This is a simple example a register/unregister case for __wr_rare markings, which only needs a simple rare_write() call to make updates. Signed-off-by: Kees Cook --- net/core/sock_diag.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index 6b10573cc9fa..67253026106f 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c @@ -14,7 +14,7 @@ #include #include -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX]; +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __wr_rare; static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh); static DEFINE_MUTEX(sock_diag_table_mutex); static struct workqueue_struct *broadcast_wq; @@ -194,7 +194,7 @@ int sock_diag_register(const struct sock_diag_handler *hndl) if (sock_diag_handlers[hndl->family]) err = -EBUSY; else - sock_diag_handlers[hndl->family] = hndl; + rare_write(sock_diag_handlers[hndl->family], hndl); mutex_unlock(&sock_diag_table_mutex); return err; @@ -210,7 +210,7 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld) mutex_lock(&sock_diag_table_mutex); BUG_ON(sock_diag_handlers[family] != hnld); - sock_diag_handlers[family] = NULL; + rare_write(sock_diag_handlers[family], NULL); mutex_unlock(&sock_diag_table_mutex); } EXPORT_SYMBOL_GPL(sock_diag_unregister);