Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2655194imm; Sun, 12 Aug 2018 20:27:36 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw0ex6So+2enrI9w3wl5zENH0Cxms7EoA7gZNBuOetlvGVoOF/HdOAHUdDfK0221SZWefX5 X-Received: by 2002:a17:902:82c7:: with SMTP id u7-v6mr14929749plz.83.1534130856230; Sun, 12 Aug 2018 20:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534130856; cv=none; d=google.com; s=arc-20160816; b=iajtA50Ygvf7zHnDsSLA43P/0ujwGNm4Rv3xgfkSkRxfPh3b+c2rtM2Onlp9BoTI77 78ouDKrBoCcy9XvY4fXtXJRsCgo8DbviJ8afYbw1/PXFzBb1CE2lov1Xaw0WCI8Ec+Wt Ph/ZEFj38n4lj7sVNIsJ2SYt0/VujXL1cWECg17ySgfYvWXrb++JaXm4VMWrN5im7CDe ivu6UqQOry/WrSfRCB3sTOouBdpaUxp31ctMg+w3bsszZ6LmgOJoGTM4MwJTxhZduJjV hg2IhtedlnAFAo1GegyEr09inVoE2pCZaC0CuxKOCLzfjcA2+TVe1PgwFVhJ9ZoRKpkD PSFA== 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:arc-authentication-results; bh=smitzV2APopDrlajmqrNET5vu+gR4RtdSjeAu12yHZ8=; b=t+NXOFclhHb7/ykmBmi2D43mJzBrnYqI7xjyRkE04Af8Up15Hx9Foor+LvBqj/gfFr xp5HOs05gkbo6UycbGzu8RY9Smod7N9WrdJK8tuk91ZcOUoUxct4rKxqYF1pteBoP0q1 hrX6IKewvFAX1MID2cv4PE0kFmwFDxQX+j4KgHVu0DXB/xJ1iI2ok+V2uYOtnpL18CYr NFf0gSBljxeminL2GnuariQCt5bK+f5GrqWI+w3z2i61dXrGWQZafk6OaS2bmEmIzeio GhrtCp3J/keRwaWq0SCoBQlxaJKlrflXo0cDbmVtF38TyqCriCbr7UiLmN3gZfVPnOEb upRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q+FAA2Bz; 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 p185-v6si17027650pga.476.2018.08.12.20.27.21; Sun, 12 Aug 2018 20:27:36 -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=Q+FAA2Bz; 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 S1728165AbeHMGGN (ORCPT + 99 others); Mon, 13 Aug 2018 02:06:13 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:39396 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725896AbeHMGGN (ORCPT ); Mon, 13 Aug 2018 02:06:13 -0400 Received: by mail-pl0-f68.google.com with SMTP id w14-v6so6327766plp.6 for ; Sun, 12 Aug 2018 20:25:56 -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=smitzV2APopDrlajmqrNET5vu+gR4RtdSjeAu12yHZ8=; b=Q+FAA2BznbSVjbKuhlI6m2Tv9lg27KIaviPRpavR6VECH4kZL1mhKmdUOJ567xay8y GBh84Va/Pkjgpfl8XOMTbYvhoLIK1gbuzYExzqnIj7NmbO7MO6muOSYI3M43d3UMcYF6 TLGaPDBmoaqcd/dJcjn5ydkZNTsG4ffLhrNHzi/dLuqQ/XSaBkKQdnLMoJf0njH8dWU+ obvY9sdWhxr2xHWCv6lEXr+qeSrtV5KfMP2De/fu6PolzS4Ip2Y2ZiHQerDjg3bWs476 43eg64opNM4UeyQMRLAAz8Jp5SYQLJRVllMn+0aYKjftgt8RWIUOGt06mWxQ1UAgvBFp 0uAg== 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=smitzV2APopDrlajmqrNET5vu+gR4RtdSjeAu12yHZ8=; b=o201cDrXnhs8RGx8sfY+RUi1adnLLaYwOFH3DI7t5UvzzvvpMVcToGLpFBo8siyiye whq2PrW6zadpUcgqis2RLdd1pYoQ1OaPpKck0vHQTh9Qq5yKSsdAvb1wp7x+IZQgCwjl rvX0CfYatvoWJ5HZlhVAb13WlNN4Lic81hvBgvZL4/ns6dElTgxnZPQEYI2cx9MWTvUO HYCrHMrvchFuCwebBixslGNhoiwtbu2LANWjrSeLE7P3DV5w4Q8BT6wNWyVxs7Uts98l 9oe8aeE5AHBCtsf34J2djmH4T4gczHneE3SoBZXh2kMGMu1w3cA2CrdUQu4D/jlxZLZh hozg== X-Gm-Message-State: AOUpUlG0UYZCejhdmLV+wQMUP8ajVamLzfOd1fA2EF6kjlnnG/iTNV4C dGyq0kupFera0tcNeUqyhV8= X-Received: by 2002:a17:902:988a:: with SMTP id s10-v6mr14848345plp.200.1534130756582; Sun, 12 Aug 2018 20:25:56 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:1c12:d766:6865:caf9]) by smtp.gmail.com with ESMTPSA id v30-v6sm27095721pgn.80.2018.08.12.20.25.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Aug 2018 20:25:56 -0700 (PDT) From: Jia-Ju Bai To: dwmw2@infradead.org Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] fs: jffs2: fix a sleep-in-atomic-context bug in jffs2_alloc_refblock() Date: Mon, 13 Aug 2018 11:25:47 +0800 Message-Id: <20180813032547.3156-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 The kernel may sleep with holding a spin lock. The function call paths (from bottom to top) in Linux-4.16 are: [FUNC] kmem_cache_alloc(GFP_KERNEL) fs/jffs2/malloc.c, 188: kmem_cache_alloc in jffs2_alloc_refblock fs/jffs2/malloc.c, 221: jffs2_alloc_refblock in jffs2_prealloc_raw_node_refs fs/jffs2/wbuf.c, 164: jffs2_prealloc_raw_node_refs in jffs2_block_refile fs/jffs2/wbuf.c, 927: jffs2_block_refile in jffs2_flash_writev fs/jffs2/wbuf.c, 924: spin_lock in jffs2_flash_writev To fix it, GFP_KERNEL in kmem_cache_alloc() is replaced with GFP_ATOMIC. This is found by my static analysis tool (DSAC). Signed-off-by: Jia-Ju Bai --- fs/jffs2/malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c index ce1189793288..66496ef09716 100644 --- a/fs/jffs2/malloc.c +++ b/fs/jffs2/malloc.c @@ -185,7 +185,7 @@ static struct jffs2_raw_node_ref *jffs2_alloc_refblock(void) { struct jffs2_raw_node_ref *ret; - ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL); + ret = kmem_cache_alloc(raw_node_ref_slab, GFP_ATOMIC); if (ret) { int i = 0; for (i=0; i < REFS_PER_BLOCK; i++) { -- 2.17.0