Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp330587pxu; Tue, 5 Jan 2021 12:09:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeJFn+zNGj2H8bVCcC9yTdhSlxiEqfITIjXeAB5/i5kTInywO65d+44kP4oHqK7JSgehkg X-Received: by 2002:a50:b765:: with SMTP id g92mr1452052ede.317.1609877349739; Tue, 05 Jan 2021 12:09:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609877349; cv=none; d=google.com; s=arc-20160816; b=jfgM0C6XsQhx42jnwitg57GQaT7FJEObASbll0vNRso/jAiltc6Y82wBdvlMOTDnR9 0tivungKssqq5enzWuSmJCqPaLV74J079fjij3pbzXgo/fsGUH8bDCukjP0DX8brLJnk wxU21/hSFVT3cSm2zzdJqDgR/4qgL8CuTOoh6Zl+is8TY1oAuIsgTMUc+FUe5PtrL4C8 qP1W6XtuxOca5KTITfeCwI2pGQtwua0cxz0eZMEfRwl3EHHVl6v/gMhDA7yrbXTa26ZA 6SPFfqqN4XY5OHb0uEakBrWj4Hjj4eax7iKC2k15lXUcijwGNlJKA5wX6SWRGVg1J07R F3lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date; bh=9S4dfd0DeCDXOggyOfNBvIDGSPJKmUF1Vdz4BBECk9A=; b=B/HTDdQ8LBlBO/+r2OjokllIR1gOF09lW3Kl3Bbq6VFMA/Dehi8JCC04M4zTIy0ti6 f6YIsgx7JxO0QLe4u26UG9nMdD3togUJFawWpjt+XJ8omjstbAAG69w2kb9NcjS/VCIf I5VfcgjbdbdGwZhzwDRq31VqUK2shPucP+O5dzVBgqw1zv1SuVIv57gqGuC3ZamZl7EJ sGUR88sWrl1LTEj+gI+16QDgzO0lpS3speWHgVMimQk9r8tlIuNHAAIoEzp2CQ9L92Z1 lEsX6dnIeo56SyrI238hTN3L7yMT0uGwKqCDcfKONFiKdeMwERgJx0e9n9EoqysYFuGR 4MCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z7si22401edm.477.2021.01.05.12.08.46; Tue, 05 Jan 2021 12:09:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729712AbhAELkl (ORCPT + 99 others); Tue, 5 Jan 2021 06:40:41 -0500 Received: from mx2.suse.de ([195.135.220.15]:50918 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728203AbhAELkl (ORCPT ); Tue, 5 Jan 2021 06:40:41 -0500 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 5F2EDAA7C; Tue, 5 Jan 2021 11:39:59 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 53C32DA7C6; Tue, 5 Jan 2021 12:38:10 +0100 (CET) Date: Tue, 5 Jan 2021 12:38:10 +0100 From: David Sterba To: bodefang Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] fs/btrfs: avoid null pointer dereference if reloc control has not been initialized Message-ID: <20210105113810.GL6430@suse.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, bodefang , clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <1609080931-4048864-1-git-send-email-bodefang@126.com> <20210104151113.GG6430@twin.jikos.cz> <125f3257.193a.176d084a633.Coremail.bodefang@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <125f3257.193a.176d084a633.Coremail.bodefang@126.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I'm keeping the rest of the mail as I received it, it's completely garbled and would need manual reformatting. The changelog and even the diff are completely on one line(!). On Tue, Jan 05, 2021 at 11:08:42AM +0800, bodefang wrote: > Similar to commmit<389305b2aa68>(“btrfs: relocation: Only remove reloc rb_trees if reloc control has been initialized”).it turns out that fs_info::reloc_ctl can be NULL in btrfs_recover_relocation() as we allocate relocation control after allreloc roots have been verified.,so there should be a check for rc to prevent null pointer dereference. > > Signed-off-by: Defang Bo Reviewed-by: David Sterba --- Oh and don't add reviewed-by unless it's explicitly stated by the person. > Changes since v1: > - More accurate description for this patch to describe how the NULL can get there. > --- > --- fs/btrfs/relocation.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 3602806..ca03571 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -626,6 +626,9 @@ static int __must_check __add_reloc_root(struct btrfs_root *root) struct mapping_node *node; struct reloc_control *rc = fs_info->reloc_ctl; + if (!rc) + return 0; + node = kmalloc(sizeof(*node), GFP_NOFS); if (!node) return -ENOMEM; @@ -703,6 +706,9 @@ static int __update_reloc_root(struct btrfs_root *root) struct rb_node *rb_node; struct mapping_node *node = NULL; struct reloc_control *rc = fs_info->reloc_ctl; + + if (!rc) + return 0; spin_lock(&rc->reloc_root_tree.lock); rb_node = rb_simple_search(&rc->reloc_root_tree.rb_root, -- 2.7.4 > > > > > > > > > > > > > > > > > > At 2021-01-04 23:11:13, "David Sterba" wrote: > >On Sun, Dec 27, 2020 at 10:55:31PM +0800, Defang Bo wrote: > >> Similar to commmit<389305b2>, > > > >Please use full commit reference like 389305b2aa68 ("btrfs: relocation: > >Only remove reloc rb_trees if reloc control has been initialized") > > > >> it turns out that fs_info::reloc_ctl can be NULL , > > > >Please describe how the NULL can get there.