From patchwork Mon Jun 19 23:36:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9798107 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 4F1BF60381 for ; Mon, 19 Jun 2017 23:44:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49B1D1FFB9 for ; Mon, 19 Jun 2017 23:44:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D14927F92; Mon, 19 Jun 2017 23:44: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 D43371FFB9 for ; Mon, 19 Jun 2017 23:44:02 +0000 (UTC) Received: (qmail 5984 invoked by uid 550); 19 Jun 2017 23:43:37 -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 5426 invoked from network); 19 Jun 2017 23:43:29 -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=Ol07kSxtyw9v50oT1BMG5Er7s0+Ncj3MRiZZHmUfdsI=; b=M1Sif/KeOiF2e0ZuAw/HUoM2kcbXvlm5vm6RtlMk/UuSoj/aAu7qI9I7sJLDPMCd3g 2LFH/1bitjJi/d6A1efE45QREjC6n4kTBqQwo7lJZ+qnp1yn5nxrSZ2GUUhZy9J+IAfP l0LDr58dXuKNynToixGhFFl1HxHeSerma+ir8= 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=Ol07kSxtyw9v50oT1BMG5Er7s0+Ncj3MRiZZHmUfdsI=; b=n8LBM0d4QYzYiic5PSu16RFfl+X+ewjJIPNL8TGgu+3dKs/Xa6a12jySWHdBSvaWI8 Sr+MBIlH7mbj/8gjdfJjQiX4F4yKuM3MyyKaGrIgN09RL9VdEsZt1I8t9dc0my0IVvkm 5EzyMyAv9Qnluq7yeOiTNolxeuaAOVRWlZCKON5rOJa59uvPU1wZvxJAtwOEFd58Vdce zEkY+YehW2RPMkIJj1Uo2QCUwRxmG1aitzNdEeI+5nYl4sgf9+Mx++Gl0guKca+cTbe+ ukszfrsbhc78xLi/U0Epl7pOckaqNAG4HjOSo7e1eImIFmNwv6aNSR/BYNF0S2ZGOrCF eDKw== X-Gm-Message-State: AKS2vOwbb57SYB+zGuuQ5uDha3Pt4mwK8WaHkCVK87k/1cTOfS20qRie XAfzLngZX8um+zZG X-Received: by 10.99.121.1 with SMTP id u1mr4271068pgc.20.1497915798397; Mon, 19 Jun 2017 16:43:18 -0700 (PDT) From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: Kees Cook , David Windsor , linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 19 Jun 2017 16:36:33 -0700 Message-Id: <1497915397-93805-20-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497915397-93805-1-git-send-email-keescook@chromium.org> References: <1497915397-93805-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 19/23] xfs: define usercopy region in xfs_inode slab cache X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor XFS inline inode data, stored in struct xfs_inode_t.i_df.if_u2.if_inline_data and therefore contained in the xfs_inode slab cache, needs to be copied to/from userspace. In support of usercopy hardening, this patch defines a region in the xfs_inode slab cache in which userspace copy operations are allowed. 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: adjust commit log] Signed-off-by: Kees Cook --- fs/xfs/kmem.h | 10 ++++++++++ fs/xfs/xfs_super.c | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/xfs/kmem.h b/fs/xfs/kmem.h index d6ea520162b2..b3f02b6226b3 100644 --- a/fs/xfs/kmem.h +++ b/fs/xfs/kmem.h @@ -100,6 +100,16 @@ kmem_zone_init_flags(int size, char *zone_name, unsigned long flags, return kmem_cache_create(zone_name, size, 0, flags, construct); } +static inline kmem_zone_t * +kmem_zone_init_flags_usercopy(int size, char *zone_name, unsigned long flags, + size_t useroffset, size_t usersize, + void (*construct)(void *)) +{ + return kmem_cache_create_usercopy(zone_name, size, 0, flags, + useroffset, usersize, construct); +} + + static inline void kmem_zone_free(kmem_zone_t *zone, void *ptr) { diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 455a575f101d..b6963baa3ac8 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1828,9 +1828,12 @@ xfs_init_zones(void) goto out_destroy_efd_zone; xfs_inode_zone = - kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode", + kmem_zone_init_flags_usercopy(sizeof(xfs_inode_t), "xfs_inode", KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD | - KM_ZONE_ACCOUNT, xfs_fs_inode_init_once); + KM_ZONE_ACCOUNT, + offsetof(xfs_inode_t, i_df.if_u2.if_inline_data), + sizeof_field(xfs_inode_t, i_df.if_u2.if_inline_data), + xfs_fs_inode_init_once); if (!xfs_inode_zone) goto out_destroy_efi_zone;