Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp19306pxb; Fri, 15 Jan 2021 04:51:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5lumFymGYPUrwV3z+MujjDmnY9oqInfxbeypolDVOSOrx+C+WrOFeytKazd1PaZdyB1a6 X-Received: by 2002:a17:906:2f83:: with SMTP id w3mr9032253eji.292.1610715084506; Fri, 15 Jan 2021 04:51:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610715084; cv=none; d=google.com; s=arc-20160816; b=RBMVGQPXsaLS+r0bOCQHd2KK+t+9DAS+muehgMrDqHcK8ybvY+EHeMm6X4GHvPAyS3 ON0aiGK7nwHdGgNnLG9p0RpTm29opNOC9R0UINbsSBnmuFotzSpuFLHzi/50AdB7Q5nu QzlXg39SQl1ye1/jKdJTeUfYDNcA1V66zBkdpBRZSZJtFaOa3BAU+fOWJEw7YGhJPhzC eIFRKWozKqOp/rNjs133AdQuyrUJv8PMumVL6IWAq8RGnigtYolkcDMNfeGnuRvrd96u xOlDMC/36+TnCMgis5ME0i4amksGuPe9HGr9KXCCE9FHhsW//Nz0b1uMBZgmlPIrGBaD 9g5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=54YpH9HitO4vQsnf944z4xKWz/9uj7dzK9Hao8tdnVs=; b=DVBpqnmf1qdW1l1hHF26ohT/neffHHIg3CPOLeLJ5QURBuFUurO4q86xXuAnK3M2tH Ia8S2z3I8pvEiZRclbYqTQ9BtA/xCMIjwK462nMSXZTT6tujTG8JFs3ESYgIBmDvUj+A +dFyJm4zbQo76ViWBf4xwMRCxMxOPJpKhNlGgs4T+tLPMLE5X9xrAK3qwwiPruPdIIl/ LINqGWl0nithytgsz1THmRsO74OzMKqZokOe5yiLg/V8FvTsoMrFS+cbStHP42UVsTBg 5JjPH8kGIdCdTUFHaaF0N6zZJn9RcLKBfObgYY9FvhtGrBrH3ovKg482+h5iHosRfqu0 /YJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JnSrrlWk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a25si4267721edn.257.2021.01.15.04.51.00; Fri, 15 Jan 2021 04:51:24 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JnSrrlWk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733312AbhAOMue (ORCPT + 99 others); Fri, 15 Jan 2021 07:50:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:43284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387843AbhAOMgK (ORCPT ); Fri, 15 Jan 2021 07:36:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C52D2256F; Fri, 15 Jan 2021 12:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714129; bh=uwX8JnIcndwYpuPkzdGR55ObxwDXNLAG2wfRJZyatHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JnSrrlWkhweH4HvGuhPUHKA5+IKvp0fDV3AmaJlYGQmAX2ZvPWMM9yBqzI+YsxZyT 7mdKACeAtVw6n0SSGQsoVHd20vZVoSX0cFaUcW3It0oRb3J+YYrCJ93w+ADZhuQ5X2 KUtv7RSCSN7wf7/cXQgaSaOJr+NirIRr4WGyn9RY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+825f0f9657d4e528046e@syzkaller.appspotmail.com, Ming Lei , Christoph Hellwig , Jens Axboe Subject: [PATCH 5.4 60/62] block: fix use-after-free in disk_part_iter_next Date: Fri, 15 Jan 2021 13:28:22 +0100 Message-Id: <20210115122001.288620591@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ming Lei commit aebf5db917055b38f4945ed6d621d9f07a44ff30 upstream. Make sure that bdgrab() is done on the 'block_device' instance before referring to it for avoiding use-after-free. Cc: Reported-by: syzbot+825f0f9657d4e528046e@syzkaller.appspotmail.com Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/genhd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/block/genhd.c +++ b/block/genhd.c @@ -222,14 +222,17 @@ struct hd_struct *disk_part_iter_next(st part = rcu_dereference(ptbl->part[piter->idx]); if (!part) continue; + get_device(part_to_dev(part)); + piter->part = part; if (!part_nr_sects_read(part) && !(piter->flags & DISK_PITER_INCL_EMPTY) && !(piter->flags & DISK_PITER_INCL_EMPTY_PART0 && - piter->idx == 0)) + piter->idx == 0)) { + put_device(part_to_dev(part)); + piter->part = NULL; continue; + } - get_device(part_to_dev(part)); - piter->part = part; piter->idx += inc; break; }