From patchwork Thu Jan 11 02:02:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10156533 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 CAD02605BA for ; Thu, 11 Jan 2018 02:08:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA95228718 for ; Thu, 11 Jan 2018 02:08:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF1EF2871D; Thu, 11 Jan 2018 02:08:38 +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=-2.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, URIBL_BLACK 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 AAE6428718 for ; Thu, 11 Jan 2018 02:08:37 +0000 (UTC) Received: (qmail 31821 invoked by uid 550); 11 Jan 2018 02:04:07 -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: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 30238 invoked from network); 11 Jan 2018 02:03:46 -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=aUFMhz/KGzkgUG61AiDnvDa/DuksW6igaYCzXCSgYSw=; b=BMtK1bmqrUKOiyk4fkdTCA81g9+Wct7eXaegQbRbS3GsxQ948E5BFrQnxBt9BW6NWA fcbUwrGKEtoCJQnIlRkgPGyT+BK8LBSaJRZc67/dLoLXPW16k5ualAB9t6fEBjtY3r0Z ku1y8gZXwgHOlsAa6dXY1RKfOu6jkMAMg8Vbg= 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=aUFMhz/KGzkgUG61AiDnvDa/DuksW6igaYCzXCSgYSw=; b=oEuJTm+IkTVg8eOp2kpGNZy7QO8CdMhqPTt9xFAXofmvBFccP6bjqUylydQJDaYn12 JeNKxnjzEl6MW0l64tTgT7aBkjyhq6ld8Y2hG4O2N41uHWZ7jKuYbPZ00lIBDRPJpUXE 0hmEUeGyemtf5/MYT5fOgzmgNfdev51u/Qr4Ns5qBfmem3P/NpwE6LeQ/JU1/5gMTDbw N4kgGmk+bgMy5Vc3ao6gOY4D9AgWgVGjCHc700SiUJNKVJ184a2jpLRkh/tN4k9ZUW1C qFyXCCyXQnjctwYRmQMGdGEr2cjrFSOgMgHe6/3EXMiJVhQdhFZi5fJlPM6uneJT29// PxFQ== X-Gm-Message-State: AKGB3mJ61E4neBxhLDdwGi140FBGzjxIEhFp/YjCYAQXfkkyU26tVzZC ouYFKXCeuIHujJxcO6G1ALB+jw== X-Google-Smtp-Source: ACJfBotS+pIeNe4kjgeA0rTE+sDHRmmU5x4y1UDAhtbVGGzGRpzvS34uBBxk7+dOr3SLK9PEkol8VA== X-Received: by 10.98.76.136 with SMTP id e8mr18833677pfj.215.1515636215261; Wed, 10 Jan 2018 18:03:35 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , 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 Date: Wed, 10 Jan 2018 18:02:56 -0800 Message-Id: <1515636190-24061-25-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> Subject: [kernel-hardening] [PATCH 24/38] ip: Define usercopy region in IP proto slab cache X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor The ICMP filters for IPv4 and IPv6 raw sockets need to be copied to/from userspace. In support of usercopy hardening, this patch defines a region in the struct proto slab cache in which userspace copy operations are allowed. example usage trace: net/ipv4/raw.c: raw_seticmpfilter(...): ... copy_from_user(&raw_sk(sk)->filter, ..., optlen) raw_geticmpfilter(...): ... copy_to_user(..., &raw_sk(sk)->filter, len) net/ipv6/raw.c: rawv6_seticmpfilter(...): ... copy_from_user(&raw6_sk(sk)->filter, ..., optlen) rawv6_geticmpfilter(...): ... copy_to_user(..., &raw6_sk(sk)->filter, len) 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: split from network patch, provide usage trace] Cc: "David S. Miller" Cc: Alexey Kuznetsov Cc: Hideaki YOSHIFUJI Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook --- net/ipv4/raw.c | 2 ++ net/ipv6/raw.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 33b70bfd1122..1b6fa4195ac9 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -970,6 +970,8 @@ struct proto raw_prot = { .hash = raw_hash_sk, .unhash = raw_unhash_sk, .obj_size = sizeof(struct raw_sock), + .useroffset = offsetof(struct raw_sock, filter), + .usersize = sizeof_field(struct raw_sock, filter), .h.raw_hash = &raw_v4_hashinfo, #ifdef CONFIG_COMPAT .compat_setsockopt = compat_raw_setsockopt, diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 761a473a07c5..08a85fabdfd1 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -1272,6 +1272,8 @@ struct proto rawv6_prot = { .hash = raw_hash_sk, .unhash = raw_unhash_sk, .obj_size = sizeof(struct raw6_sock), + .useroffset = offsetof(struct raw6_sock, filter), + .usersize = sizeof_field(struct raw6_sock, filter), .h.raw_hash = &raw_v6_hashinfo, #ifdef CONFIG_COMPAT .compat_setsockopt = compat_rawv6_setsockopt,