From patchwork Mon Aug 28 21:35:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9926339 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 BC6C260375 for ; Mon, 28 Aug 2017 21:45:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B17E2287D5 for ; Mon, 28 Aug 2017 21:45:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6445287D6; Mon, 28 Aug 2017 21:45: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=-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 AA7C9287DA for ; Mon, 28 Aug 2017 21:45:12 +0000 (UTC) Received: (qmail 9606 invoked by uid 550); 28 Aug 2017 21:44:12 -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 9452 invoked from network); 28 Aug 2017 21:44:07 -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=vxhon9t2UjiizQZuDjtE51VC0d5DMIosc49T7BwPFrA=; b=KzjyIwiNyDaebElkH5e2NUMCR+iKci+g9lzyVAbBGvZQ6ubvJSmIX626NYztERjj4J BTjIDWuDPAVB5cTwk5khZD2FZ5T+4VtoWBz1vvANmeW4T+bWXzfs366JK5siH0HRGNYg mZswoQIBaRUESV4i3oty/wdHWihgJeyEg86fk= 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=vxhon9t2UjiizQZuDjtE51VC0d5DMIosc49T7BwPFrA=; b=FrcYRmfj4/0AiHZNUgXUeXZq35KYVFfS9I/Q64lh4IFZ4RH1nxLlSplGxgMHM/9a+j rqI8RcmodeJghkvQogIaygP2PDFMcF7xj180KQH37i/5RXgH5DA2HDGGUvSQK65Z3hY7 IS9R8+Bu4MtdLhM2sF5Oe6vL1H6WsWn4X1zW8Jr5fEttMTGC82JeX+PSMiuVldDy5MBD +qXtRJ/bfUSxFuaZw1W6OrYM5bUFKw2jtEbsspdauJRklLiDeajduMpiUsxJRDzoaqhD 8m1ErJstSTYlsKmBXS2pHqcKocTSmQRiHfJejztZGUOzPYDTNL9F/ivXOw8Vs6ZRvEXb MKeQ== X-Gm-Message-State: AHYfb5hWpqgZI4q3eZW1uGKNUIYSZhvwxWTm5YnK6nQfVUMuO6OrxVzi wbMJe69n11jkTHNP X-Received: by 10.84.211.137 with SMTP id c9mr2420469pli.356.1503956635648; Mon, 28 Aug 2017 14:43:55 -0700 (PDT) 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, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Date: Mon, 28 Aug 2017 14:35:00 -0700 Message-Id: <1503956111-36652-20-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503956111-36652-1-git-send-email-keescook@chromium.org> References: <1503956111-36652-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH v2 19/30] 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 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 b0bb5d0a30bd..6c7f8d2eb3af 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -964,6 +964,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 60be012fe708..27dd9a5f71c6 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -1265,6 +1265,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,