From patchwork Mon Aug 28 21:35:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9926347 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 7108F60329 for ; Mon, 28 Aug 2017 21:45:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63F08287A5 for ; Mon, 28 Aug 2017 21:45:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 543A1287D7; Mon, 28 Aug 2017 21:45:47 +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 AD919287D6 for ; Mon, 28 Aug 2017 21:45:45 +0000 (UTC) Received: (qmail 9788 invoked by uid 550); 28 Aug 2017 21:44:17 -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 9526 invoked from network); 28 Aug 2017 21:44:09 -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=UKatO1gLtRqX3aqTd9wE75GOeS3kdlJYf3ZMjJeA9oM=; b=VyupHHLkksmag6GtHY/1UVDgel4XXKpavxgQqDilnnQDtLuxOEPuUemWIiyIyLbfVU 7tVLuMZEPHa37PfVq4/1PskVjXVofgvHJT8rR+wtr3p2jeXb4VHTu65Y9pLykE0pRShk 9efalgFJIL+rZO+pjgkKbw3dG/X+6oG5EcEMs= 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=UKatO1gLtRqX3aqTd9wE75GOeS3kdlJYf3ZMjJeA9oM=; b=Dv7Ld5SMNHh1DO1puR+AmKFUgKKenLO1ejlzKEg/ssZ54fr7pXlAJ5O2Gi8Cnm9vAv UA447ZeCT8VcDn0t+B+KuVusZEYGZSYkGc97iZbFgR1n6KlW0dHoADxovOoxzMfZdxUI Ltefv+ytO3f2vu5FAITj23FejlgbKABf05MMkolVyl/ir7iOIHUcAIb4f5Vttoe9zyif kMcXMpT4OoSglZtE9LwF4eeLKBMRUALv0QlqoErWCrPFWMVr3IvPeVg5/4g59tMXz9C6 AjTe73DDNRAwbuCrJ/pmiK0CZhpJwGtJ81C7o46Hmjg4R8QNXTicRw5Up9BmS0fmIlwV HCGQ== X-Gm-Message-State: AHYfb5i3aP1oSfC82nuQjHaHuceycIgcO9hUpB71rF4eG/MPTWxVm9lu p86F24ssstALxuSfHgWrXQ== X-Received: by 10.84.210.196 with SMTP id a62mr2367142pli.382.1503956638262; Mon, 28 Aug 2017 14:43:58 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , Vlad Yasevich , Neil Horman , "David S. Miller" , linux-sctp@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Date: Mon, 28 Aug 2017 14:35:02 -0700 Message-Id: <1503956111-36652-22-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 21/30] sctp: Define usercopy region in SCTP proto slab cache X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor The SCTP socket event notification subscription information 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. Additionally moves the usercopy fields to be adjacent for the region to cover both. example usage trace: net/sctp/socket.c: sctp_getsockopt_events(...): ... copy_to_user(..., &sctp_sk(sk)->subscribe, len) sctp_setsockopt_events(...): ... copy_from_user(&sctp_sk(sk)->subscribe, ..., optlen) sctp_getsockopt_initmsg(...): ... copy_to_user(..., &sctp_sk(sk)->initmsg, 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, move struct member adjacent, provide usage] Cc: Vlad Yasevich Cc: Neil Horman Cc: "David S. Miller" Cc: linux-sctp@vger.kernel.org Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook --- include/net/sctp/structs.h | 9 +++++++-- net/sctp/socket.c | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index 5ab29af8ca8a..f1d7810e200e 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -202,12 +202,17 @@ struct sctp_sock { /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */ __u32 param_flags; - struct sctp_initmsg initmsg; struct sctp_rtoinfo rtoinfo; struct sctp_paddrparams paddrparam; - struct sctp_event_subscribe subscribe; struct sctp_assocparams assocparams; + /* + * These two structures must be grouped together for the usercopy + * whitelist region. + */ + struct sctp_event_subscribe subscribe; + struct sctp_initmsg initmsg; + int user_frag; __u32 autoclose; diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 1db478e34520..c8784cb216e4 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -8235,6 +8235,10 @@ struct proto sctp_prot = { .unhash = sctp_unhash, .get_port = sctp_get_port, .obj_size = sizeof(struct sctp_sock), + .useroffset = offsetof(struct sctp_sock, subscribe), + .usersize = offsetof(struct sctp_sock, initmsg) - + offsetof(struct sctp_sock, subscribe) + + sizeof_field(struct sctp_sock, initmsg), .sysctl_mem = sysctl_sctp_mem, .sysctl_rmem = sysctl_sctp_rmem, .sysctl_wmem = sysctl_sctp_wmem,