Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2538459yba; Mon, 6 May 2019 07:41:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbi/H02oWHVzWJh/lztrUEt+vpeyEXDaWRi7fDVTKcQLFIzyVxwfPIjyI6MtmHnjbqDCcB X-Received: by 2002:a63:cd50:: with SMTP id a16mr31652743pgj.394.1557153699160; Mon, 06 May 2019 07:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557153699; cv=none; d=google.com; s=arc-20160816; b=Hs4JFws6i6wuE7V9h/W2hiMl+1JLOqL/jEAPeYl0bR6HdY2sQY9ptrsNfphfrJHhsW z/fUjhaKDINJDpX9gHr7tI138DJplE2Pqh/YpojWpbLgx/0mfJ8M6y/O4ctB/RDbeYZ+ zpRENHsM6vQ/+zvxIsuIKQ2bcjRmRyWLZ/C0b9CuWWeOx8LM0Nlioo2oHVOXwHOSNVZc YvGSK5pJ+5Ewtpc/NQ2+TpO888pvhTwzOqdPh27zGoP0lVMqWHRw2/3/JBYPsSjp1GOh G+MobNBqB/Cqo5x+LSczSNXRN+MWc502FkdcBRzIS+0i3LXpnz/W4Hmo7Yj9T6DRaEVW e9Nw== 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=ItFZ1GqaKK7BBTMnumQvWLusLEv2pqZEPdFJII5pyE8=; b=vsLGdsELMj5OI+WwOdCAJkEw4zk4gU7CgpdSnZvjQkSq8J2prWryHCxkcwyUAzs+vq H3GLjUUbSwxHHR4QeLuluqcO6i0l/SnH+4klAuuxvcfAGBpE1MHv7+ts50IHxXz3j7H2 kLxd8qMx06bl3p55nrV+dw3M7iKQRKGsptw/BwwQyL8j8d7sFf4SsJpNzKd80i7QMITi iuY+FERssxws0vaGo4lnQC7pRia0GPc/c1yo2Q5BBVIvfGJ8F8LCFeEI/Gns0VTCyp8v lZzXK+9jQ89hc/YxxTf+boktb6wsCGWsEXyRzdwvbeKwmrEZ9k+NZYFXQuKxar0kxV8p 1W1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N+NuqAXz; 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 g9si16794621plb.38.2019.05.06.07.41.22; Mon, 06 May 2019 07:41:39 -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=N+NuqAXz; 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 S1727595AbfEFOiZ (ORCPT + 99 others); Mon, 6 May 2019 10:38:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:59422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbfEFOiV (ORCPT ); Mon, 6 May 2019 10:38:21 -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 AFD5C21479; Mon, 6 May 2019 14:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153500; bh=8S9jqxSugKzCwYoFHMOwDkEPnCxhTDlkdzKVKwSDLxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N+NuqAXzarhKnixlKP3ftsrKsFskq78bbq0QPmIwk/Ua0tsbpGxu5Av7/MxdWCGpP m7XqxdzZovOAaw9wfoZqlfyHeWgzVD7I9xW4s+Fc97Mk6GlWmk27h87fvoGQ46HeaC fJxv2q5nk8ISnOQ2pbrnlU4rCo6IADkmbHUFqwNI= 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 5.0 113/122] selinux: never allow relabeling on context mounts Date: Mon, 6 May 2019 16:32:51 +0200 Message-Id: <20190506143104.604395622@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@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 @@ -534,16 +534,10 @@ 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, "tracefs") || @@ -553,6 +547,34 @@ static int selinux_is_sblabel_mnt(struct !strcmp(sb->s_type->name, "cgroup2"))); } +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;