From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AA18C433E1 for ; Tue, 28 Jul 2020 13:41:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 271D520663 for ; Tue, 28 Jul 2020 13:41:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730144AbgG1Nlv (ORCPT ); Tue, 28 Jul 2020 09:41:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:43456 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730069AbgG1Nlv (ORCPT ); Tue, 28 Jul 2020 09:41:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 40EA4AEF6; Tue, 28 Jul 2020 13:42:01 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 8493EDA701; Tue, 28 Jul 2020 15:41:21 +0200 (CEST) Date: Tue, 28 Jul 2020 15:41:21 +0200 From: David Sterba To: Qu Wenruo Cc: dsterba@suse.cz, Qu Wenruo , linux-btrfs@vger.kernel.org, Luciano Chavez Subject: Re: [PATCH] btrfs: inode: Fix NULL pointer dereference if inode doesn't need compression Message-ID: <20200728134121.GV3703@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , Qu Wenruo , linux-btrfs@vger.kernel.org, Luciano Chavez References: <20200728083926.19518-1-wqu@suse.com> <20200728131920.GU3703@twin.jikos.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Tue, Jul 28, 2020 at 09:26:43PM +0800, Qu Wenruo wrote: > >> Fixes: 4d3a800ebb12 ("btrfs: merge nr_pages input and output parameter in compress_pages") > > > > How does this patch cause the bug? > > > Sorry, I should explain more on that. > > In fact it takes me quite some time to find the proper culprit. > > Before that commit, we have @nr_pages_ret initialized to 0 in > compress_file_extent(). > > If inode_need_compress() returned false in that function, we continue to > the same inline file extent insert,. > > But in free_pages_out: tag, we use @nr_pages_nr to free pages, which is > still 0, as it only get initialized to proper values after > btrfs_compress_pages() call, which we skipped due to > inode_need_compress() returned false. > > Then free_pages_out: tag will not execute the WARN_ON() and put_pages() > calls, just skip to kfree(pages). And kfree() can handle NULL pointers > without any problem. > > Thus a completely sane looking cleanup in fact caused the NULL pointer > dereference regression for race cases. Thanks. It was not obvious so I was expecting a bit more convoluted way to hit the bug.