Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11045750ybi; Thu, 25 Jul 2019 09:04:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxrpFysDo+MqJ6935KwyJHVC4VFgrdz12qUSfTAm+Jqhiy2BSUug/sdJuMmcxyLgNWiFiz X-Received: by 2002:a17:902:a01:: with SMTP id 1mr7468260plo.278.1564070653788; Thu, 25 Jul 2019 09:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564070653; cv=none; d=google.com; s=arc-20160816; b=Buh9tsPx3w/DHEWWxr1lZsQ7NGi68Zmtg2AV3hULRCqGroqfk2JYQdBvKosiFmRL1Q R2mdllldxVgUFnUFI+HWvttGXxddeqS/NKV+idnkvyFx2JUfzghpRGavcvn00/V3K/zG 9YL43yPKE9wzRd51K9r8wfqw65dXDLJ3WIykp9uXUKckQ7kKFLAclbmGA151zgLUA3fn i17Gzqsw8PWQvYIKvJBEk89zk9/mNLFF4n5jbGBrpW76anF5Xhs/9EwkYDuDmga7ce6e SLb517T2sqYHYaS1Abn1JFLzMaIC36L4XwPiXhvBLIeOdREfmiCtvwiJ4M+iw+qliQL7 70eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=oZzmYnbVeA3T1k/Blnoj4JLRh8hVO63J2LZYhH68rjY=; b=lFIuV/dgMfRIgPOv9MK0brYup1i9HhVxiobjzQaMrPLgsbCJro582kw0Rj6xQMb88S jgtetnV5TLmyO8NpqgzcspVBu8I3k9B8lU/1GwcZTLQ/5oKrT2w2Y0YF64D/0OsZ1Dzm DPkFYJNe3PF7Zk/NUrK9qpZjz1seoF9foLOkhka+K4Lyly5qDYR+94Vb/Dn/i3lfxsPu pauNcaa7m7RZyH4Hb0dKliD8iL76fUbffiZnyUzWSXflP667ZTFKq44Atuv9Sr6G0Inv XzUWkRWySdejyOy5WaP8stAmMzODmxBm9ckziOf1MuaKQVSupXPECPLjLH9we9Bog2k3 Gt7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=de2hdfLV; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si40622526pgk.187.2019.07.25.09.03.58; Thu, 25 Jul 2019 09:04:13 -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=@gmail.com header.s=20161025 header.b=de2hdfLV; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389985AbfGYI5l (ORCPT + 99 others); Thu, 25 Jul 2019 04:57:41 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40164 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388805AbfGYI5k (ORCPT ); Thu, 25 Jul 2019 04:57:40 -0400 Received: by mail-pl1-f193.google.com with SMTP id a93so23108151pla.7; Thu, 25 Jul 2019 01:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=oZzmYnbVeA3T1k/Blnoj4JLRh8hVO63J2LZYhH68rjY=; b=de2hdfLVt6WQzMnVVNGjoOVU+c/cmUfyzo759Q3cohTisB8QqnMCwMkYS0qpQ2EfUp 5Jo/P4+57CE7iulPyvb77tqkbLW8JuMQEiSfVNvmWv+n2UFwuEPfgH2sbh5Ek7RV/IA/ NZzt6cl0ZqpTp1rVL5XidnT6clbb2vGh7dw52tXDKAOkGD7dHEhfQ61fV/LFsvLjg3Jj d5G7vF9iMyTJ7Zs2yMQlDDXKSAHZDrIM21xFASo3DiKCGtfmCdUPieDvG4cJZIhot0Jc Os3wq8E0Rc7y6n5alGUsRV3jp1Tys1RUJIOUEWZIg2FeEXHFD8tcZUTBWdLfJ+FQObjM EIRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oZzmYnbVeA3T1k/Blnoj4JLRh8hVO63J2LZYhH68rjY=; b=VNnYsIKuV4sqZwPt7kCh+wFKkTUud/0sVtKBWdBZTVfC/bmOhCLdLlv8RDUmw7i97f aBiidsjyp7G12X28SsQivDtIjc4YD84/2tyrrhXgT6nkG/uJ6OcEqc1XlMK5W5touTLT NkE1WRmn37lU5SKTs9Rlz9+04bbpbJ2napqi1kZ41TUkZpDHcvWDANc1sOb9ZyfZlYip lW4vYEjVbKu25MLjTH9JzUuXn2nr/0+VXHQ+agp1ya4DQ2fLeWH8LledZ0/kQRfVAq89 f6Blon6nPjngdHvc1/looQr+RAyERn0SRWGKx0NJnZNEbH1LvtTHEjMCWRM+gTwyuMqg Pmhw== X-Gm-Message-State: APjAAAViIvFKttUF8Wz9KMjlBVjzxRhjegXImzFFik28NOaaXbvOvNIS HGjZ5SKWjrmTVeVJk17kVWLIUaGDH+c= X-Received: by 2002:a17:902:4623:: with SMTP id o32mr88427211pld.112.1564045059699; Thu, 25 Jul 2019 01:57:39 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id f14sm48865966pfn.53.2019.07.25.01.57.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jul 2019 01:57:39 -0700 (PDT) From: Jia-Ju Bai To: miklos@szeredi.hu Cc: linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] fs: overlayfs: Fix a possible null-pointer dereference in ovl_free_fs() Date: Thu, 25 Jul 2019 16:57:32 +0800 Message-Id: <20190725085732.15674-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In ovl_fill_super(), there is an if statement on line 1607 to check whether ofs->upper_mnt is NULL: if (!ofs->upper_mnt) When ofs->upper_mnt is NULL and d_make_root() on line 1654 fails, ovl_free_fs() on line 1683 is executed. In ovl_free_fs(), ofs->upper_mnt is used on line 224: ovl_inuse_unlock(ofs->upper_mnt->mnt_root); Thus, a possible null-pointer dereference may occur. To fix this bug, ofs->upper_mnt is checked before being used in ovl_free_fs(). This bug is found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- fs/overlayfs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index b368e2e102fa..1d7c3d280834 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -220,7 +220,7 @@ static void ovl_free_fs(struct ovl_fs *ofs) if (ofs->workdir_locked) ovl_inuse_unlock(ofs->workbasedir); dput(ofs->workbasedir); - if (ofs->upperdir_locked) + if (ofs->upperdir_locked && ofs->upper_mnt) ovl_inuse_unlock(ofs->upper_mnt->mnt_root); mntput(ofs->upper_mnt); for (i = 0; i < ofs->numlower; i++) { -- 2.17.0