From patchwork Mon Dec 7 21:21:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7791431 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 C4AAFBEEE1 for ; Mon, 7 Dec 2015 21:54:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 214832052F for ; Mon, 7 Dec 2015 21:54:10 +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 0913720461 for ; Mon, 7 Dec 2015 21:54:08 +0000 (UTC) X-TM-IMSS-Message-ID: <3e68e0c400028a3c@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 3e68e0c400028a3c ; Mon, 7 Dec 2015 16:52:09 -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 tB7LiT8D003463; Mon, 7 Dec 2015 16:51:31 -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 tB7LQWtX263193 for ; Mon, 7 Dec 2015 16:26:32 -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 tB7LNOqA001405 for ; Mon, 7 Dec 2015 16:26:32 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CeBABD9WVW/6zfVdFeGQEBAQEPAQEBAYRLuxeEFoYOAoITAQEBAQEBhUABAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iR4ExPjGKV4VUAQWLdQEBAQEBBQIBGgYKhDqCEI44jiSIQpZNhiGLbjaBF2OCBA0dgXVTAYVuAQEB X-IPAS-Result: A1CeBABD9WVW/6zfVdFeGQEBAQEPAQEBAYRLuxeEFoYOAoITAQEBAQEBhUABAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iR4ExPjGKV4VUAQWLdQEBAQEBBQIBGgYKhDqCEI44jiSIQpZNhiGLbjaBF2OCBA0dgXVTAYVuAQEB X-IronPort-AV: E=Sophos;i="5.20,396,1444708800"; d="scan'208";a="5004905" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 07 Dec 2015 16:23:33 -0500 X-TM-IMSS-Message-ID: <3e4ea1e100028022@nsa.gov> Received: from mail-io0-f172.google.com (mail-io0-f172.google.com [209.85.223.172]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 3e4ea1e100028022 ; Mon, 7 Dec 2015 16:23:29 -0500 Received: by ioc74 with SMTP id 74so4001820ioc.2 for ; Mon, 07 Dec 2015 13:23:31 -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=Tn/8XbrU48ajIIQJ8pAVpXJttwX51UJxHYDEZrwjomOVW/zsNZSv1NJJXjgt8nsZ2M JcoBwiJlh/k7/KApCaGGwafhvImsOfoVfnn2Dl496RIHumaxfP42gxNzoHjkkeYoTOvl V20Ij25gVWHljVuYkbiesEtxxAnp3aUnAPC/aY9v7VvKk3Xohcg/cw3LUYVPqj33sgys MWX/x5bGawY+yLaYxhTgi6gFAaolp5X0rZG5XN+6SYQvgP4NB6ZnzUb5hDA3JroHFjxe WBKH0oqK0PHP24Ok422Xu/CIspjeW0D4PLzSC/HSpDPhunGgNtp/Ma21QAh/JTAZy5WV xGbQ== 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=ELIjf6dxRIuWnM8M7vuiw0QUzgXtMXcHNb2/lZBI8D9/kDrHVd6GEVlaAysztgxWhB LN4kfobbPoMWkr/yhGQkrjDEzdMKiAcVSWB0i2sCE3LxgRun7pHETpdi5mdd4LzyB9qk N45FnY1KAKcm4e6dL3aIBTyiT3DdPWT5VA2fiaNM+pgCSFOOijN3HGqlAVxiavm4fgdz 74pyjMYjhoRNBozCeW2MTcBB9P55V4M9yasBWZVBPNylqma4FXVPiCizKtlzpxLHipvf Y+znXCfMCJ0ZW4pX1m/oHe0FuPwMmyRYFYIXw2c0GjQ7fvQ2Gq1Sbj7JJWgvErXL/kf3 19Rg== X-Gm-Message-State: ALoCoQlsAIoWVgSCc3qZRcbjP+SvjV5krG29/7VKsRwdGcm4wjZ1TuUDspo3mDJHwcRiFLQZCpY8jmM5+YNJ+xSyeXa/e8L9BQ== X-Received: by 10.107.186.3 with SMTP id k3mr622355iof.43.1449523411495; Mon, 07 Dec 2015 13:23:31 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id 15sm204695iob.33.2015.12.07.13.23.30 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 07 Dec 2015 13:23:31 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH v2 09/18] fs: Refuse uid/gid changes which don't map into s_user_ns Date: Mon, 7 Dec 2015 15:21:18 -0600 Message-Id: <1449523289-144238-10-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449523289-144238-1-git-send-email-seth.forshee@canonical.com> References: <1449523289-144238-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Mon, 07 Dec 2015 16:44:28 -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;