From patchwork Thu Jan 11 02:02:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10156651 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 AD93560231 for ; Thu, 11 Jan 2018 02:16:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99B522874C for ; Thu, 11 Jan 2018 02:16:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CF1F2874F; Thu, 11 Jan 2018 02:16:13 +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=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, URIBL_BLACK autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 054192874C for ; Thu, 11 Jan 2018 02:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754250AbeAKCPz (ORCPT ); Wed, 10 Jan 2018 21:15:55 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:38472 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753978AbeAKCJj (ORCPT ); Wed, 10 Jan 2018 21:09:39 -0500 Received: by mail-pg0-f68.google.com with SMTP id t67so1631578pgc.5 for ; Wed, 10 Jan 2018 18:09:38 -0800 (PST) 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=LFWRCd/+LnQ+jgsEC7h8LYDXfoIkGuadoUBcvax4iD0=; b=MpnCeMYBBNPLdJqWWlbRW7Htd8KO9MSJK/JjGGrey2+6DbEjxLZOBXnE6wVU2igdUF EaCLiYwGWQmeE0r64CtKQeQN1KVorK5e27nTZFatS5AO6U4L4ogMTAzyEK8nL+2HPIeb qmud0IW49lVQuTfZSg/GzwXqFIa2k4bmBS4io= 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=LFWRCd/+LnQ+jgsEC7h8LYDXfoIkGuadoUBcvax4iD0=; b=ZRYD8LPBWeUAkgpKK4M9u676y2Jhb+5IWXEsVkg+FDCxaXgBON/juUqKtFecFjBCad 5oNncL4rAmt+fDJwNrTuWCk38zRnOEuBzn0pgjpcv4N2RvaSw3DgTvPP2UB6qA4BuwcX t5ejLextefwH5CrRE7SDjmF1gD/WXDhRq1/CppaI8e/9u9KjEgI5/wiKuDcLOdDB6gLm oQnhXcXQJFlZ6cFF6Xom6NcPpHIw2UHdC8LN6WOXhDqbkID0us2i0W3INkUZ6kCWW6uA C+J9gmXhjInfeyqm7MdE/YwzVNTgkBGW6LB3/7zZkUjmlsrrf5fuWsgKHPCmZHE+0hm3 ruxA== X-Gm-Message-State: AKGB3mL7e/RxqbVLzs7prjWTf+Q5AR7E7GEgivVtalgnoTV63XF3iKl+ vgVdd93O67vQHUndo26Edi3+lA== X-Google-Smtp-Source: ACJfBosEQKdOz4QHJ4BClJ/koojDAc8rt+fjthgaV3o1MlJOxMhU8A6BlGYU2cbw1mfzif+auuXpqg== X-Received: by 10.159.253.143 with SMTP id q15mr21425377pls.32.1515636578584; Wed, 10 Jan 2018 18:09:38 -0800 (PST) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id d5sm11298128pfk.2.2018.01.10.18.09.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2018 18:09:33 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , "David S. Miller" , Eric Dumazet , Paolo Abeni , David Howells , netdev@vger.kernel.org, Linus Torvalds , Alexander Viro , Andrew Morton , Andy Lutomirski , Christoph Hellwig , Christoph Lameter , Laura Abbott , Mark Rutland , "Martin K. Petersen" , Paolo Bonzini , Christian Borntraeger , Christoffer Dall , Dave Kleikamp , Jan Kara , Luis de Bethencourt , Marc Zyngier , Rik van Riel , Matthew Garrett , linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Subject: [PATCH 23/38] net: Define usercopy region in struct proto slab cache Date: Wed, 10 Jan 2018 18:02:55 -0800 Message-Id: <1515636190-24061-24-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515636190-24061-1-git-send-email-keescook@chromium.org> References: <1515636190-24061-1-git-send-email-keescook@chromium.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor In support of usercopy hardening, this patch defines a region in the struct proto slab cache in which userspace copy operations are allowed. Some protocols need to copy objects to/from userspace, and they can declare the region via their proto structure with the new usersize and useroffset fields. Initially, if no region is specified (usersize == 0), the entire field is marked as whitelisted. This allows protocols to be whitelisted in subsequent patches. Once all protocols have been annotated, the full-whitelist default can be removed. This region is known as the slab cache's usercopy region. Slab caches can now check that each dynamically sized copy operation involving cache-managed memory falls entirely within the slab's usercopy region. This patch is modified from Brad Spengler/PaX Team's PAX_USERCOPY whitelisting code in the last public patch of grsecurity/PaX based on my understanding of the code. Changes or omissions from the original code are mine and don't reflect the original grsecurity/PaX code. Signed-off-by: David Windsor [kees: adjust commit log, split off per-proto patches] [kees: add logic for by-default full-whitelist] Cc: "David S. Miller" Cc: Eric Dumazet Cc: Paolo Abeni Cc: David Howells Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook --- include/net/sock.h | 2 ++ net/core/sock.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/net/sock.h b/include/net/sock.h index 79e1a2c7912c..b77a710ee831 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1112,6 +1112,8 @@ struct proto { struct kmem_cache *slab; unsigned int obj_size; slab_flags_t slab_flags; + size_t useroffset; /* Usercopy region offset */ + size_t usersize; /* Usercopy region size */ struct percpu_counter *orphan_count; diff --git a/net/core/sock.c b/net/core/sock.c index c0b5b2f17412..261e6dbf0259 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3151,8 +3151,12 @@ static int req_prot_init(const struct proto *prot) int proto_register(struct proto *prot, int alloc_slab) { if (alloc_slab) { - prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0, + prot->slab = kmem_cache_create_usercopy(prot->name, + prot->obj_size, 0, SLAB_HWCACHE_ALIGN | prot->slab_flags, + prot->usersize ? prot->useroffset : 0, + prot->usersize ? prot->usersize + : prot->obj_size, NULL); if (prot->slab == NULL) {