From patchwork Fri Jun 22 21:43:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 933617 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41CBss5WH1z9s3C; Sat, 23 Jun 2018 07:44:17 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1fWTqg-0004Kn-V9; Fri, 22 Jun 2018 21:44:06 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1fWTqf-0004Kd-AQ for kernel-team@lists.ubuntu.com; Fri, 22 Jun 2018 21:44:05 +0000 Received: from mail-it0-f71.google.com ([209.85.214.71]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1fWTqf-000298-0D for kernel-team@lists.ubuntu.com; Fri, 22 Jun 2018 21:44:05 +0000 Received: by mail-it0-f71.google.com with SMTP id n66-v6so4080796itg.0 for ; Fri, 22 Jun 2018 14:44:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=7FdMzrJUjql+gD1R4nY79CKGZ8j42h3LhOk4MoIDMq0=; b=ptNOMmqSvG9y864YUVy+dzY1XIj+9eecvmJZLqmf8aHKBkCdsWy/tc+o/ZtpOvggAL dIIPGr4Em7nHWSSJXTXBNYq7QrtJmAmXGKxs/p3iDSjvUKyJ/oMkz1cOR7a/dvjgABm2 wkmADasWW66v+xk/aUpYs848rww2IK91acbkmaR1C4JFc647zKEKXFcHq+ggqDtKTzuM PTtfCJLhokXiUCgAg9WHcdDzs60oCClBwMIWDQ2mmAa3Nn1/XW/ozdzVsoL6B2pa7Be1 PFywFDcA1AxvMQd5GWH+lJqWQYPgRYC81/1w1A9LKx9BaaP2eCm/6QckAaQp2ZFFMkJQ LiTA== X-Gm-Message-State: APt69E0ITUzWAJmGSzJAlC5QR3EATjR39N1tn0+sYirUIk4qiGJXQJJU lHdmGxrUHWXr9WKoZrjLT7xCt2pnDuIPT9CTxBdRmRtDNvVzrDgzp1PRLL9hghNUCm9Aa00lLOO dNQZvEJr/3rzHKACQaSxIUZ3f8dBf+esrdr4M6Ykxpg== X-Received: by 2002:a6b:2286:: with SMTP id i128-v6mr2802750ioi.289.1529703843788; Fri, 22 Jun 2018 14:44:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf7i/zML9wIpLbl2pBflJC/pG8r4FRgaJYaJ9vlGriAA7jgQMkQHSCunI2o0SdijuNPUGgIHA== X-Received: by 2002:a6b:2286:: with SMTP id i128-v6mr2802740ioi.289.1529703843536; Fri, 22 Jun 2018 14:44:03 -0700 (PDT) Received: from localhost ([2605:a601:ac7:2a20:110:4491:9f96:3555]) by smtp.gmail.com with ESMTPSA id k139-v6sm1285503itk.27.2018.06.22.14.44.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Jun 2018 14:44:02 -0700 (PDT) From: Seth Forshee To: kernel-team@lists.ubuntu.com Subject: [SRU][Xenial][PATCH 2/4] commoncap: move assignment of fs_ns to avoid null pointer dereference Date: Fri, 22 Jun 2018 16:43:57 -0500 Message-Id: <20180622214359.17903-3-seth.forshee@canonical.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180622214359.17903-1-seth.forshee@canonical.com> References: <20180622214359.17903-1-seth.forshee@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Colin Ian King BugLink: http://bugs.launchpad.net/bugs/1778286 The pointer fs_ns is assigned from inode->i_ib->s_user_ns before a null pointer check on inode, hence if inode is actually null we will get a null pointer dereference on this assignment. Fix this by only dereferencing inode after the null pointer check on inode. Detected by CoverityScan CID#1455328 ("Dereference before null check") Fixes: 8db6c34f1dbc ("Introduce v3 namespaced file capabilities") Signed-off-by: Colin Ian King Cc: stable@vger.kernel.org Acked-by: Serge Hallyn Signed-off-by: James Morris (backported from commit 76ba89c76f2c74e208d93a9e7c698e39eeb3b85c) Signed-off-by: Seth Forshee --- security/commoncap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/security/commoncap.c b/security/commoncap.c index c730ed00f427..6b4a8788c753 100644 --- a/security/commoncap.c +++ b/security/commoncap.c @@ -596,13 +596,14 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data struct vfs_ns_cap_data data, *nscaps = &data; struct vfs_cap_data *caps = (struct vfs_cap_data *) &data; kuid_t rootkuid; - struct user_namespace *fs_ns = inode->i_sb->s_user_ns; + struct user_namespace *fs_ns; memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data)); if (!inode || !inode->i_op->getxattr) return -ENODATA; + fs_ns = inode->i_sb->s_user_ns; size = inode->i_op->getxattr((struct dentry *)dentry, XATTR_NAME_CAPS, &data, XATTR_CAPS_SZ); if (size == -ENODATA || size == -EOPNOTSUPP)