From patchwork Tue Jan 9 20:55:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10153389 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 957C060223 for ; Tue, 9 Jan 2018 21:02:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D72B25404 for ; Tue, 9 Jan 2018 21:02:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E93626255; Tue, 9 Jan 2018 21:02:21 +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 7C51925404 for ; Tue, 9 Jan 2018 21:02:20 +0000 (UTC) Received: (qmail 9755 invoked by uid 550); 9 Jan 2018 20:57:36 -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 9229 invoked from network); 9 Jan 2018 20:57:20 -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=GYMFju1GmggA97KjERN9iZ2gpFg5cO1xOIbpQKD795Y=; b=QDHc4LSQPic9NW8CRyeL/WB8AYGM/YY3zK0IoUl5BI/sgghhDyfKGNp2cD0uI7+RSM RhuZMhbaLmRVGFcCXdrxRsqUX+dwarGfCQFNwu4OmPgX/8h8h+GEp0Fdq//pxTnAIoBv CX5HSPYWlwN1RQGABrkrXS9tthIn4tMJ+dfZU= 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=GYMFju1GmggA97KjERN9iZ2gpFg5cO1xOIbpQKD795Y=; b=qZvTg9OcAtvHIK1e/OMD4GW7hQ1YSKsn1L1gJsaFtXMDklYyZlS1H18jON0RF/oXcg 6fneSr/ZbsHSQj4ZztzfMGYb/0VYG71aJAONj5KXfo8BO3maa6+77Kz+CjaMPNkqILxF 3mLXbb6VXz07MbCFcAILS/FTiwRNfhR/lNoog+gPKQzxZ8TSmebDRYcXM3fDfSA8Y7Hw a/26VjfauBnvLub2qFoZX/vgW3zLQWMMdSDV0RCfQ4Nes99IN57AaYRRPHVadltYRMOS 6t7+75X9dL+bIjrl+d4FKw5In8r9j5guWr1iWrZX+0XXQfOUw9EwneSoaLZSyyEbWgcz v/dw== X-Gm-Message-State: AKGB3mKJuzXBPHDeU+x4/6ETTUfFbaHl510VbvLImdMlug8wBCzUq4lG RIIuxwu2hNUIiDGFLSSBAfiOXg== X-Google-Smtp-Source: ACJfBosGy0fSFNNOudUppXc2BlzonSUIdL6vPIbG/qtLB6WcB/OSPEkLRscNVqS1Qgmqd5EWtImARA== X-Received: by 10.159.196.141 with SMTP id c13mr16397447plo.15.1515531429327; Tue, 09 Jan 2018 12:57:09 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , "David S. Miller" , Eric Dumazet , Paolo Abeni , David Howells , netdev@vger.kernel.org, Linus Torvalds , David Windsor , 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: Tue, 9 Jan 2018 12:55:54 -0800 Message-Id: <1515531365-37423-26-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515531365-37423-1-git-send-email-keescook@chromium.org> References: <1515531365-37423-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 25/36] net: Restrict unwhitelisted proto caches to size 0 X-Virus-Scanned: ClamAV using ClamSMTP Now that protocols have been annotated (the copy of icsk_ca_ops->name is of an ops field from outside the slab cache): $ git grep 'copy_.*_user.*sk.*->' caif/caif_socket.c: copy_from_user(&cf_sk->conn_req.param.data, ov, ol)) { ipv4/raw.c: if (copy_from_user(&raw_sk(sk)->filter, optval, optlen)) ipv4/raw.c: copy_to_user(optval, &raw_sk(sk)->filter, len)) ipv4/tcp.c: if (copy_to_user(optval, icsk->icsk_ca_ops->name, len)) ipv4/tcp.c: if (copy_to_user(optval, icsk->icsk_ulp_ops->name, len)) ipv6/raw.c: if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen)) ipv6/raw.c: if (copy_to_user(optval, &raw6_sk(sk)->filter, len)) sctp/socket.c: if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen)) sctp/socket.c: if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len)) sctp/socket.c: if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len)) we can switch the default proto usercopy region to size 0. Any protocols needing to add whitelisted regions must annotate the fields with the useroffset and usersize fields of struct proto. 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. Cc: "David S. Miller" Cc: Eric Dumazet Cc: Paolo Abeni Cc: David Howells Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook --- net/core/sock.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/core/sock.c b/net/core/sock.c index 261e6dbf0259..f39206b41b32 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3154,9 +3154,7 @@ int proto_register(struct proto *prot, int alloc_slab) 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, + prot->useroffset, prot->usersize, NULL); if (prot->slab == NULL) {