From patchwork Wed Jul 20 23:49:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 12924612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2EA7C433EF for ; Wed, 20 Jul 2022 23:50:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E66BB6B0072; Wed, 20 Jul 2022 19:50:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E14AB6B0073; Wed, 20 Jul 2022 19:50:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D04C66B0074; Wed, 20 Jul 2022 19:50:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C1CA66B0072 for ; Wed, 20 Jul 2022 19:50:12 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 999781406FD for ; Wed, 20 Jul 2022 23:50:12 +0000 (UTC) X-FDA: 79709124264.28.793F5BB Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by imf18.hostedemail.com (Postfix) with ESMTP id D3CC31C0090 for ; Wed, 20 Jul 2022 23:50:10 +0000 (UTC) Received: from fsav313.sakura.ne.jp (fsav313.sakura.ne.jp [153.120.85.144]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 26KNo1kl081032; Thu, 21 Jul 2022 08:50:02 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav313.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav313.sakura.ne.jp); Thu, 21 Jul 2022 08:50:01 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav313.sakura.ne.jp) Received: from [192.168.1.9] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 26KNo13i081027 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Thu, 21 Jul 2022 08:50:01 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Thu, 21 Jul 2022 08:49:57 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH] mm: memcontrol: fix potential oom_lock recursion deadlock Content-Language: en-US From: Tetsuo Handa To: Johannes Weiner , Michal Hocko , Andrew Morton Cc: linux-mm References: <000000000000471c2905e3c2c2c2@google.com> <20220714141813.yi5p4o2tiyvkao6b@quack3> <534fa596-0c29-0f1e-b292-53ad9c3dbbe3@I-love.SAKURA.ne.jp> <20220715013908.ayyimue5yhfwonho@google.com> <03304bf8-d153-698f-0376-9e9a0ec1048e@I-love.SAKURA.ne.jp> In-Reply-To: <03304bf8-d153-698f-0376-9e9a0ec1048e@I-love.SAKURA.ne.jp> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658361011; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1JU5uE2Nfz1HPqDm7MEWFTWgwgz9U4Mj5Vm05zjwxOI=; b=YTcqau31nYFtCq5JNRIUc7HCsY0Qsi2o+IHZVQo1UpBwmIMkWx1T3+c1kGbkLmthJUE0Lk Wz1k9BSaD4ErvrtQYHtG07vx2A7ICo+PQ85a2gse6lO+Aew1kT2ROAPQuXTDme2b4A8MLW v5589aa5vxwzFaJVS7XAH7FKMUKKF2U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658361011; a=rsa-sha256; cv=none; b=cHmBysZcHFfBnRegdZX2ZfzXcoX2GKY4a/AoDZ4Lms6TcO5i3XLu7kSGuViYNr+eJEE9+w 5NBnysODAzP3Iabziz8afOyWROJEK+/jAQsug+ne0rOz0IvTZ6JEmLR/b6vYogc2+KlmnN MBZEOsW/7vwShph3TOXDY1Lgl1zgE0Q= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=none (imf18.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp X-Rspamd-Queue-Id: D3CC31C0090 Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=none (imf18.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: qyedax4q9ge7jy8ycdfo7j3ra1w8nt6e X-HE-Tag: 1658361010-32621 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: syzbot is reporting fs_reclaim allocation with oom_lock held [1]. We must make sure that such allocation won't hit __alloc_pages_may_oom() path which will retry forever if oom_lock is already held. I choose GFP_ATOMIC than GFP_NOWAIT, for since global OOM situation will likely be avoided by killing some process in memcg, and memory will be released after printk(), trying a little hard will be acceptable. Link: https://syzkaller.appspot.com/bug?extid=2d2aeadc6ce1e1f11d45 [1] Reported-by: syzbot Fixes: c8713d0b23123759 ("mm: memcontrol: dump memory.stat during cgroup OOM") Signed-off-by: Tetsuo Handa --- mm/memcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 618c366a2f07..11cd900729b9 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1465,7 +1465,8 @@ static char *memory_stat_format(struct mem_cgroup *memcg) struct seq_buf s; int i; - seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE); + /* Caller might be holding oom_lock. */ + seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_ATOMIC), PAGE_SIZE); if (!s.buffer) return NULL;