From patchwork Wed Dec 2 15:40:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7748651 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 12BEBBEEE1 for ; Wed, 2 Dec 2015 16:33:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 631F120549 for ; Wed, 2 Dec 2015 16:33:22 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (emvm-gh1-uea08.nsa.gov [63.239.67.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 87B7C20503 for ; Wed, 2 Dec 2015 16:33:21 +0000 (UTC) X-TM-IMSS-Message-ID: <2383b87f00017d16@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1) id 2383b87f00017d16 ; Wed, 2 Dec 2015 11:31:44 -0500 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tB2GVP25011831; Wed, 2 Dec 2015 11:31:32 -0500 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id tB2FgZtN185601 for ; Wed, 2 Dec 2015 10:42:35 -0500 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tB2FgWlH006648 for ; Wed, 2 Dec 2015 10:42:35 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1ChAAA0EF9Wm7LVVdFeGQEBAQEPAQEBAYRMu3CEFoYOAoIYAQEBAQEBEgEBAQEBBgsLCSGEYwEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaEVgTE+MYpXhVQBBYwjAQEBAQEFAgEaBgqEOoIQjjaOIIhBlkyGIYtrNoEXgmcNFgeBdVMBhW4BAQE X-IPAS-Result: A1ChAAA0EF9Wm7LVVdFeGQEBAQEPAQEBAYRMu3CEFoYOAoIYAQEBAQEBEgEBAQEBBgsLCSGEYwEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaEVgTE+MYpXhVQBBYwjAQEBAQEFAgEaBgqEOoIQjjaOIIhBlkyGIYtrNoEXgmcNFgeBdVMBhW4BAQE X-IronPort-AV: E=Sophos;i="5.20,373,1444708800"; d="scan'208";a="4986122" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 02 Dec 2015 10:42:25 -0500 X-TM-IMSS-Message-ID: <2356b0b200015ee1@nsa.gov> Received: from mail-ig0-f178.google.com (mail-ig0-f178.google.com [209.85.213.178]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 2356b0b200015ee1 ; Wed, 2 Dec 2015 10:42:33 -0500 Received: by igcmv3 with SMTP id mv3so120229769igc.0 for ; Wed, 02 Dec 2015 07:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F6DHgWVc3nkRbgh1dVw6jfQtAywZIA/MSQXS2nxBBFE=; b=abqtq8M29gVLNtaTCwUPmuRCwDbwzdfmjt6reDcbSkBtUVeySSsOski71jE0AfVYAG 27cg/tc0pUEJR5cZCLfwxa3F9dH1oPoTcNR2fl6ZPx9C45IGMI/wU4kSK3yD7qc1nJSO 4Txa2Z4FyoybSmuzpcT/aXmY9AaXkUlI+VFRtP9bgDJE8fnmlDZ2iJUQPKEW8+sN6o0r 52U+Syf70AQqPhHRjx8o0CVE+RFnikBIVJ9eNyBkGIERv8HSWQ4g28jhaciorzqEnqCO 2fD15hkwVEQH6+iauxvZBJMXR+Es8fzqxJPgtDeciU0Umi9D8TWiw//qw43sIpED/7Wz jnKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F6DHgWVc3nkRbgh1dVw6jfQtAywZIA/MSQXS2nxBBFE=; b=OvfYlciKHUgcVx8Hnal2Ke5LDsrK3r2kSZnHXQUICMC6LFTn/e55r8IDYdN0V9y8Mv jDPxQqOD9GB6cSOWnZGiVej2cUcUf9WXpFsAgbXIvCx8oU+EnZttXXIYF+jsjqlJYOkT E7kfoS3O8D4rP6+j7Yd6990EC1noSVEVjy7Ka5BO3/0E+hQ0oU/Jn0Ys5jPTSX8hfwjd DGxQW3ZmR+A0eDOBdLCc+yYEEPBNbSyemrVrwxapSkc1HE5b0/PU8CXVZDBXQh5o95Uz pyEzonTQebUleJtql+MaV5Wd0SubkfoSuzzR0N7LyaLqc0/LOMJEbDfmBpg6e5t2GFrd fiFQ== X-Gm-Message-State: ALoCoQlj4gsi/BgGWt7FwBMSieQHZkcP5HZ7q1pKVLy62GvQB3sVUamYKwUdAbpt78oE5jG778a6 X-Received: by 10.50.20.138 with SMTP id n10mr4511143ige.11.1449070943981; Wed, 02 Dec 2015 07:42:23 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id vs11sm11487427igb.6.2015.12.02.07.42.23 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Dec 2015 07:42:23 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH 09/19] fs: Refuse uid/gid changes which don't map into s_user_ns Date: Wed, 2 Dec 2015 09:40:09 -0600 Message-Id: <1449070821-73820-10-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449070821-73820-1-git-send-email-seth.forshee@canonical.com> References: <1449070821-73820-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Wed, 02 Dec 2015 11:15:49 -0500 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: Cc: Serge Hallyn , Seth Forshee , dm-devel@redhat.com, Miklos Szeredi , Richard Weinberger , linux-security-module@vger.kernel.org, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, fuse-devel@lists.sourceforge.net, Austin S Hemmelgarn , linux-mtd@lists.infradead.org, selinux@tycho.nsa.gov, linux-fsdevel@vger.kernel.org MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add checks to inode_change_ok to verify that uid and gid changes will map into the superblock's user namespace. If they do not fail with -EOVERFLOW. This cannot be overriden with ATTR_FORCE. Signed-off-by: Seth Forshee Acked-by: Serge Hallyn --- fs/attr.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/attr.c b/fs/attr.c index 6530ced19697..55b46e3aa888 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -42,6 +42,17 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr) return error; } + /* + * Verify that uid/gid changes are valid in the target namespace + * of the superblock. This cannot be overriden using ATTR_FORCE. + */ + if (ia_valid & ATTR_UID && + from_kuid(inode->i_sb->s_user_ns, attr->ia_uid) == (uid_t)-1) + return -EOVERFLOW; + if (ia_valid & ATTR_GID && + from_kgid(inode->i_sb->s_user_ns, attr->ia_gid) == (gid_t)-1) + return -EOVERFLOW; + /* If force is set do it anyway. */ if (ia_valid & ATTR_FORCE) return 0;