From patchwork Mon Jan 4 18:03:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7950271 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 D67E1BEEE5 for ; Mon, 4 Jan 2016 18:49:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3718720320 for ; Mon, 4 Jan 2016 18:49:21 +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 9E27D2034A for ; Mon, 4 Jan 2016 18:49:19 +0000 (UTC) X-TM-IMSS-Message-ID: <75de209500104540@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 75de209500104540 ; Mon, 4 Jan 2016 13:47:20 -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 u04IkQ0m017839; Mon, 4 Jan 2016 13:46:28 -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 u04I4iAh225792 for ; Mon, 4 Jan 2016 13:04:44 -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 u04I4gpJ013588 for ; Mon, 4 Jan 2016 13:04:44 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CSAAAys4pWm7DfVdFeGQEBAQEPAQEBAYRJiFm1aIYPAoFoAQEBAQEBEgEBAQEBBgsLCSGEYwEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaJOgTE+MYpXhVQBBYweAQEBAQEFAgEaBgqEO4IRjjuONYhWlmqFYkSMKjWBF4JoDRUHHYFfUwGFDwEBAQ X-IPAS-Result: A1CSAAAys4pWm7DfVdFeGQEBAQEPAQEBAYRJiFm1aIYPAoFoAQEBAQEBEgEBAQEBBgsLCSGEYwEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaJOgTE+MYpXhVQBBYweAQEBAQEFAgEaBgqEO4IRjjuONYhWlmqFYkSMKjWBF4JoDRUHHYFfUwGFDwEBAQ X-IronPort-AV: E=Sophos;i="5.20,521,1444708800"; d="scan'208";a="5070754" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 04 Jan 2016 13:04:27 -0500 X-TM-IMSS-Message-ID: <75b67ce700103481@nsa.gov> Received: from mail-io0-f176.google.com (mail-io0-f176.google.com [209.85.223.176]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 75b67ce700103481 ; Mon, 4 Jan 2016 13:04:02 -0500 Received: by mail-io0-f176.google.com with SMTP id o67so442123852iof.3 for ; Mon, 04 Jan 2016 10:04:26 -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=+GJhNqrqnF7KyQXWHgC62ejdycKfPe5y+hcsS+l4lw8=; b=JQL1Nf/aUafJVkgkUdAOxqEdoIf9ii7mtyOk3QfiW7Y68KylMVHncmMjnMBgg76Kzo Ov9Xm0+KCmEFsAisbxT0zt3peRqE3aGPNPXMSycECAjwwHZ6O6soT9fTMPiLM/gX3t3/ 88uExdcZ/RCHHU2KRFKsk+eYr4r7098fQv4R7KHq3vGJxLu5qwRNCHAi9GdG4I5xHLuc OEiHKUzo9D4yrVGU+I5fSri30Gd0iWD2t8EmjHCVreBlto26JI+Kji/grJ08bk6RA1YC Qt0z5P0KFxqdiY153VWL8MQWblBp5J4B4o6h+ePNtY8Zp9k0GqtxUAj8hgwJtTXLXpvu BJRQ== 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=+GJhNqrqnF7KyQXWHgC62ejdycKfPe5y+hcsS+l4lw8=; b=SI26Tqi5XdR6T7oQvxjwcMQ2+fhgef0Fi2mrcJDk39MW5MiQYQjGqkJ3ECpYb3zA5C WFl1/CYCBRwRbdbGQQ5X2lR5lbec0A9yuE91pT3tO9+AVpe+d0QXC+iqZrL7VPWsvMLi uo2lAcQffZvEUtxbAT3JIzjem+2KI5gVAQxbZyCFQBhf1TEvdu5ZHt0+E02YcL3cv9aI WKigZtUkIfdc3AqpRuxNMMYJrG1vsDGIiA19WflnLLQPqsUBHnYyH+tud8GKMCpPDqf9 l95c9gFGSfjTFTes1g5p1xqyPb1zAudB/SMfUlnIRToqKVL7XngqbGGjUG0Bl5HGA5I2 elFw== X-Gm-Message-State: ALoCoQk3+jd7WAkCA6+AH/UkllwdTHUKSGsyKjTOhIR6L4swjrdy7iQZsqatgh6j+s8BDLuv2t19fk0KswK2X0rJr+KQ6XC4Lg== X-Received: by 10.107.40.76 with SMTP id o73mr20596103ioo.157.1451930665915; Mon, 04 Jan 2016 10:04:25 -0800 (PST) Received: from localhost ([66.64.121.229]) by smtp.gmail.com with ESMTPSA id h187sm32443310ioh.4.2016.01.04.10.04.25 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 04 Jan 2016 10:04:25 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH RESEND v2 09/18] fs: Refuse uid/gid changes which don't map into s_user_ns Date: Mon, 4 Jan 2016 12:03:48 -0600 Message-Id: <1451930639-94331-10-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451930639-94331-1-git-send-email-seth.forshee@canonical.com> References: <1451930639-94331-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Mon, 04 Jan 2016 13:14:22 -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,RP_MATCHES_RCVD,T_DKIM_INVALID,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;