Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2548792yba; Mon, 6 May 2019 07:51:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvBhBH7/SZoNcrBIW7yxMl2PoXXA0a+Wu5x0hTWBRJVQPpsG2RDADtxVRpmifF6WsRMhB/ X-Received: by 2002:a17:902:8604:: with SMTP id f4mr31764976plo.245.1557154293501; Mon, 06 May 2019 07:51:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557154293; cv=none; d=google.com; s=arc-20160816; b=VGCvmbZQcXvTvXH6qJlwOHkmBfMJ8k3MG+OTqFaRuzNb7sIq0Nq9GC2thz5HRoeMf0 lYBJHH3qY7979EHYbVk3JOMVGnhgqVaO5LXkidthaVZwpPZdr2tXHBO7AVL0v4N2yO4t azRZ4VkfV9a+H9JWrTqhkifugAXEwxgY4kBOgYfy/TmAti8zODgDIEz7KDiiPc9MOFwq 32CuI7LRZwzXHiRw8JPA4X0TEk1qSXgu1DOXETAdr+rq6BrvuVHtA8TpeI7NS6xBBZIX ryj2vs5jb+ixH4G8MER4L92Y6zZU1aBgDkuj010HHQcnZeHyYOck/W1C3hXRTPTxcof9 woaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oASsiHFwOPVeLoBKBTjI+/Px2iPb2R72cK/UQDFDoNw=; b=ri59ChR3AdB9XMrVOE+kEL6u1uB3/BS3eIepxKr0vm1S+NSU+MjgJyYTFF54xnxx13 A7TA3Ud+Tinftd3laIpuuvMIALVOyHWY4EEVynVmo0j90T+KcAofGYyilaZzok6IoOY+ n6riSPTcFnfobkT2v5lwhDapUpvCh5LG4AgbjTidPo1oDOgHri7amjl01oQchGW/zfFX tqqjrj4NSXksEJWMPlxmMqXWqgwuFjHhaleSRgla/Wf0EzdIskWqveRYZLqCMzJsf2xr fc/txTJ7JPN6eeqnXsxZtor6kvBhsRI8jDffIR/NL1u0Oq8RG3VhbVfkN5t1pTi9Nyzz gctQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wXv8VZ3D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si14454681pgx.176.2019.05.06.07.51.17; Mon, 06 May 2019 07:51:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wXv8VZ3D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729419AbfEFOtZ (ORCPT + 99 others); Mon, 6 May 2019 10:49:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:50864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726985AbfEFOtX (ORCPT ); Mon, 6 May 2019 10:49:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F04D121019; Mon, 6 May 2019 14:49:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557154162; bh=qW0yTp0Bkwnm33rylBQl14Ex1/xlNSpFb9hZF9+Snsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wXv8VZ3D23gRk57JxVQqb5kQ/v1APK7NibJPWqfyhZcRa0Um65Ws6VdPDcdrpA4iA yXNZ9mlY0hOuiRwv8wYfTUOPpezSXMp6KcuZH6N7U6fM811Zhb6fPzTWPYFf10tCQe +5kAbamJR/bVFgf39Ivb+XPNmwzsTjhdVPSm5Vzs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ondrej Mosnacek , Stephen Smalley , Paul Moore Subject: [PATCH 4.9 60/62] selinux: never allow relabeling on context mounts Date: Mon, 6 May 2019 16:33:31 +0200 Message-Id: <20190506143056.624747476@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143051.102535767@linuxfoundation.org> References: <20190506143051.102535767@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ondrej Mosnacek commit a83d6ddaebe541570291205cb538e35ad4ff94f9 upstream. In the SECURITY_FS_USE_MNTPOINT case we never want to allow relabeling files/directories, so we should never set the SBLABEL_MNT flag. The 'special handling' in selinux_is_sblabel_mnt() is only intended for when the behavior is set to SECURITY_FS_USE_GENFS. While there, make the logic in selinux_is_sblabel_mnt() more explicit and add a BUILD_BUG_ON() to make sure that introducing a new SECURITY_FS_USE_* forces a review of the logic. Fixes: d5f3a5f6e7e7 ("selinux: add security in-core xattr support for pstore and debugfs") Signed-off-by: Ondrej Mosnacek Reviewed-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/hooks.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -467,21 +467,43 @@ static int may_context_mount_inode_relab return rc; } -static int selinux_is_sblabel_mnt(struct super_block *sb) +static int selinux_is_genfs_special_handling(struct super_block *sb) { - struct superblock_security_struct *sbsec = sb->s_security; - - return sbsec->behavior == SECURITY_FS_USE_XATTR || - sbsec->behavior == SECURITY_FS_USE_TRANS || - sbsec->behavior == SECURITY_FS_USE_TASK || - sbsec->behavior == SECURITY_FS_USE_NATIVE || - /* Special handling. Genfs but also in-core setxattr handler */ - !strcmp(sb->s_type->name, "sysfs") || + /* Special handling. Genfs but also in-core setxattr handler */ + return !strcmp(sb->s_type->name, "sysfs") || !strcmp(sb->s_type->name, "pstore") || !strcmp(sb->s_type->name, "debugfs") || !strcmp(sb->s_type->name, "rootfs"); } +static int selinux_is_sblabel_mnt(struct super_block *sb) +{ + struct superblock_security_struct *sbsec = sb->s_security; + + /* + * IMPORTANT: Double-check logic in this function when adding a new + * SECURITY_FS_USE_* definition! + */ + BUILD_BUG_ON(SECURITY_FS_USE_MAX != 7); + + switch (sbsec->behavior) { + case SECURITY_FS_USE_XATTR: + case SECURITY_FS_USE_TRANS: + case SECURITY_FS_USE_TASK: + case SECURITY_FS_USE_NATIVE: + return 1; + + case SECURITY_FS_USE_GENFS: + return selinux_is_genfs_special_handling(sb); + + /* Never allow relabeling on context mounts */ + case SECURITY_FS_USE_MNTPOINT: + case SECURITY_FS_USE_NONE: + default: + return 0; + } +} + static int sb_finish_set_opts(struct super_block *sb) { struct superblock_security_struct *sbsec = sb->s_security;