Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp287555imm; Fri, 3 Aug 2018 03:32:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf24ZgNvwLztRjEE2eoFP+bO7a1UtAyqeZDM8CyihvJXK4Y9UO2xMmc6G4whEuHbY9Rwi4o X-Received: by 2002:a63:4a61:: with SMTP id j33-v6mr3167993pgl.436.1533292361229; Fri, 03 Aug 2018 03:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533292361; cv=none; d=google.com; s=arc-20160816; b=JiZ/pE2nH6Ay2PhuG0ZgYBo6RKpzWeor/c+nKORI5qM+D3sOnv5xXPYa/2sApgBDbi nNXVXC/3tTq0MeCXzlx/ITYDf2S4434MeKQSQDV0BXbyO97b9bWyQRqa+hOFvUbq8xnD PYkvIS4zBaLWWsvhn5YIVVfRu8q3hXfpG7SbKdEReEzlRSHHdGn4oP4CDSqR3KePqzlb CJVIZJP5Zec1R44N+M827kpe6qrZg0Ofzn+hJISPCJBw/4RzucIqsCJOf3r7bgM+7jc3 XaWkYxdqlJDrWPTEJOQoK5VfWC2PAw2ekb74GLCjoIyua1m8g1lY+43svEfudORfWOTn NJ8w== 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:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:arc-authentication-results; bh=nGYI0x7DZAxUnwopD5AdIabV3HW4JJ+oBOUfTk8ffmE=; b=b3GWcOHyQfwQmaNofD/m2ssjHyrSTGWN+p4NCDOPD7YsaG4P6nIcWoMRsKT0mN+UID LmKfStpmDY9n0vIZNa5MFdSHM2kdWotwIY8AZxYUzzXCpZRiA6fp5MLVnn7rOHc/C0bN BPxBmiluu9qJTHRD8Q5OvhxvBJoemQXasCVB+6kY3PCBTfWgXnskOPhcyWumOm+NA89l dlX43uDeq5MTj73Wqi0GB/fGnaKCV56y62QYcKvr0XC2+7B6xT3RYcQMh7VcT6CWggRF J5QvJENycHEkOyjCpYw7lnzjrDPMpK/ymsx05taoJSMpo53nHewfJ6bHnV82f6PKfbL1 nZRw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o8-v6si3534878pll.193.2018.08.03.03.32.26; Fri, 03 Aug 2018 03:32:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732674AbeHCM05 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 3 Aug 2018 08:26:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53794 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732233AbeHCM05 (ORCPT ); Fri, 3 Aug 2018 08:26:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8092D4015A56; Fri, 3 Aug 2018 10:31:15 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-78.rdu2.redhat.com [10.10.120.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 495551D085; Fri, 3 Aug 2018 10:31:13 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <47c34fad-5d11-53b0-4386-61be890163c5@virtuozzo.com> References: <47c34fad-5d11-53b0-4386-61be890163c5@virtuozzo.com> <153320759911.18959.8842396230157677671.stgit@localhost.localdomain> <20180802134723.ecdd540c7c9338f98ee1a2c6@linux-foundation.org> To: Kirill Tkhai Cc: dhowells@redhat.com, Andrew Morton , linux-kernel@vger.kernel.org, vdavydov.dev@gmail.com, mhocko@suse.com, aryabinin@virtuozzo.com, ying.huang@intel.com, penguin-kernel@I-love.SAKURA.ne.jp, willy@infradead.org, shakeelb@google.com, jbacik@fb.com, linux-mm@kvack.org Subject: Re: [PATCH] mm: Move check for SHRINKER_NUMA_AWARE to do_shrink_slab() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8346.1533292272.1@warthog.procyon.org.uk> Content-Transfer-Encoding: 8BIT Date: Fri, 03 Aug 2018 11:31:12 +0100 Message-ID: <8347.1533292272@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 10:31:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 10:31:15 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The reproducer can be reduced to: #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include const char path[] = "./file0"; int main() { mkdir(path, 0); mount(path, path, "cgroup2", 0, 0); chroot(path); umount2(path, 0); return 0; } and I've found two bugs (see attached patch). The issue is that do_remount_sb() is called with fc == NULL from umount(), but both cgroup_reconfigure() and do_remount_sb() dereference fc unconditionally. But! I'm not sure why the reproducer works at all because the umount2() call is *after* the chroot, so should fail on ENOENT before it even gets that far. In fact, umount2() can be called multiple times, apparently successfully, and doesn't actually unmount anything. David --- diff --git a/fs/super.c b/fs/super.c index 3fe5d12b7697..321fbc244570 100644 --- a/fs/super.c +++ b/fs/super.c @@ -978,7 +978,10 @@ int do_remount_sb(struct super_block *sb, int sb_flags, void *data, sb->s_op->remount_fs) { if (sb->s_op->reconfigure) { retval = sb->s_op->reconfigure(sb, fc); - sb_flags = fc->sb_flags; + if (fc) + sb_flags = fc->sb_flags; + else + sb_flags = sb->s_flags; if (retval == 0) security_sb_reconfigure(fc); } else { diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index f3238f38d152..48275fdce053 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -1796,9 +1796,11 @@ static void apply_cgroup_root_flags(unsigned int root_flags) static int cgroup_reconfigure(struct kernfs_root *kf_root, struct fs_context *fc) { - struct cgroup_fs_context *ctx = cgroup_fc2context(fc); + if (fc) { + struct cgroup_fs_context *ctx = cgroup_fc2context(fc); - apply_cgroup_root_flags(ctx->flags); + apply_cgroup_root_flags(ctx->flags); + } return 0; }