Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1513333imm; Wed, 20 Jun 2018 20:39:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKEzC4NTjD4X3a0vwd6TSpTUXhETWKAmvdRBwyiSoxxkkYn9jxaX3lV22HdYFeg3KoWKs+q X-Received: by 2002:a17:902:e187:: with SMTP id cd7-v6mr26881503plb.166.1529552376434; Wed, 20 Jun 2018 20:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529552376; cv=none; d=google.com; s=arc-20160816; b=qWRDeQc3zZUNs0S3IMtql8y5dK0TZtXQhFxHAsJQK5kuoYlNYBvOFBWc4oKQbR04Hh 344UdxrcT/dENUU19aYMpaC3uLQLzcsJP0rE2BqOhnpm39h2yV1jTePomVeGoZCxPw1Y cZ3t/yw5h/pRkIyeKDCsqSdWM+OXqD8LYfWHGsKFfVftw1D1XRYoiZL3xYZiNKWT+/fC gTELFuc4Gx1EDyX7826WS2tTJziRwleinnUZSRrLJDVvM7dImxN+KWOpt4iEnMCDV+R9 ELgz4XKWZEmZ5FxKRjDazWi4lSW9BAF5JJUYWJGUqR+jo2aq2WqpzU5VScQJQSy17kUO iVEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=QQH3ximMoywdIMrTDGm7L0+M5zE1k2bsxnYUoQNVKoE=; b=ilrbSoPGbkfXFCJXKQGCYWwRTo18Wh1VBlqZ9xuRlgSm0XGNUN115H5hdR+2WgXWeO 1Ngebfm1vVu3Gw3r0mewG/5nhmahg4U7P0+rnxYRjBxNecTWXlDCGCCBunHvwg3iQDLt CEus26tdWxmDU3QBSwLT0IQYs13KvMZpNFWIDTOMXNDkHjDHn00QCGNrhgXFuDTsXhW/ lGNwJew9uAi+4rz/qNn/b1Pt+IfccuKbo+N/+6Zc12wnXZ3wmLd83TkjH2WUe5EoDduG oqmesXC4ehpbh0anpcvZcM5r36YrL/ObPZAqpfkk1SiWG/MZ0xwznZsCJLyoCkNDm4Bk mQTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=PBRyPbYp; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 90-v6si3941855pla.38.2018.06.20.20.39.22; Wed, 20 Jun 2018 20:39: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=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=PBRyPbYp; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754259AbeFUDip (ORCPT + 99 others); Wed, 20 Jun 2018 23:38:45 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:57290 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754157AbeFUDio (ORCPT ); Wed, 20 Jun 2018 23:38:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jz6InbLPNtLdi9oExyf6Hd0WwaSMbu7MCe0lMz3eOCs=; b=PBRyPbYpHs+kd1G84r/b/zwaD 2lj6P7LQF1YHjQuxr951Qgd7TrYxMEeuwXisKDkUhLgpx2PKSI9SNfg2nF+6j0dIEl2mRXTU4PGZ5 slyMwbDbFQPjlI+BW5o2uijPwogCyVnTANS6TgXpdh4GFoJG8AjFvqZVTzMhs2JgCIPllzjYHPWEO vEdFu+gcW85hztT9LH/eQ4+Xpq2Nm1ySpWM/RUF6L6HFSvFMl8FvQ8KsdTEb/8s+945RL9LVLzA3j GVNKgAUszSt0he9OTuKPAnZR4lVt6W0qwvrB7+QCIyVn+kxuRMbxOZd52Rfdbb17srWjdrof8/wgY v8B4K2B8A==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVqQi-0008G5-5O; Thu, 21 Jun 2018 03:38:40 +0000 Date: Wed, 20 Jun 2018 20:38:39 -0700 From: Matthew Wilcox To: Jia-Ju Bai Cc: akpm@linux-foundation.org, dvyukov@google.com, gregkh@linuxfoundation.org, jthumshirn@suse.de, pombredanne@nexb.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: mempool: Fix a possible sleep-in-atomic-context bug in mempool_resize() Message-ID: <20180621033839.GB12608@bombadil.infradead.org> References: <20180621030714.10368-1-baijiaju1990@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180621030714.10368-1-baijiaju1990@gmail.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 21, 2018 at 11:07:14AM +0800, Jia-Ju Bai wrote: > The kernel may sleep with holding a spinlock. > The function call path (from bottom to top) in Linux-4.16.7 is: > > [FUNC] remove_element(GFP_KERNEL) > mm/mempool.c, 250: remove_element in mempool_resize > mm/mempool.c, 247: _raw_spin_lock_irqsave in mempool_resize > > To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC. > > This bug is found by my static analysis tool (DSAC-2) and checked by > my code review. But ... we don't use the flags argument. static void *remove_element(mempool_t *pool, gfp_t flags) { void *element = pool->elements[--pool->curr_nr]; BUG_ON(pool->curr_nr < 0); kasan_unpoison_element(pool, element, flags); check_element(pool, element); return element; } ... static void kasan_unpoison_element(mempool_t *pool, void *element, gfp_t flags) { if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) kasan_unpoison_slab(element); if (pool->alloc == mempool_alloc_pages) kasan_alloc_pages(element, (unsigned long)pool->pool_data); } So the correct patch would just remove this argument to remove_element() and kasan_unpoison_element()?