Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3432427imu; Sun, 11 Nov 2018 15:00:07 -0800 (PST) X-Google-Smtp-Source: AJdET5d/MddF6Z9/bFo+BeN06gQSPtUdBn4lUjSQcidsAYB60O2xGBx4SEr+Mo6kuj6LYpje0d5r X-Received: by 2002:a65:448a:: with SMTP id l10mr5040536pgq.387.1541977207134; Sun, 11 Nov 2018 15:00:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977207; cv=none; d=google.com; s=arc-20160816; b=jjnsWTL2xXsUs7lc2VZIx8X8vJYVfdbO4Jo8xXhzjkDIjWztfc1mFnyyEBUh8Ud8Op C4x6eLBUjQ++LhJZqG0RwQOjTPPPWLGLUIsh9YaFdo6UPtuTD+JfXGRXWKZMLwRk0fct 2ksUuneVEc/4zcTWPoJYZzEeDkvhut5/F46QPMLRLDcjIMQrO9Tklz5HqGTWb56lqHdH C8doJBx7127F3rOSgqNZhd/Zzu6586JpZgW4OLoMLsyIuQt19ehZ0IVJ5KEBFRJPQDts Ce7nixfhWEmVJLW57wyAQwno2gpMzvZZdabi/h5ukfrzEF922I8usZT9SzNG0XSZT0MZ kATw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FF7uJP7AqNwQbKZWANs3MsXdu4f2dqXue13CykT24z8=; b=mQ+S9C+8gpUSxfp3IHCx0/p6cQpvHhXhKc9g8MQgfJKjVjO8cglq4HwpWef+DAYnfH o0+6ByVYxvMLW5+9DuhyWfr63IlV/v6SXp4sWrnEWe9rw2na5gM2ebllw7qPoUtJJ8jN eMd/iyUMre6qCzEl6R9gJAnnBUsnDHCH9Xh9XRnJPpFRXumcG41rvKFBP/6eC2heR5va LUauu0hUwJ8XJJ0xj6dbKapAmlcL4C9tPOIN2H8/9RCIdKo9wDwbtQJqm7i/0MB8jU37 jA+7k0MmwVu8wZGBD5ag4C6mhLUbclQtgyD4NOooaj0XJSuJbuvcgiPC20yDLF412T1p Gawg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fZfjpYF2; 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 u8-v6si14501074pgl.59.2018.11.11.14.59.52; Sun, 11 Nov 2018 15:00:07 -0800 (PST) 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=@kernel.org header.s=default header.b=fZfjpYF2; 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 S2403783AbeKLIWn (ORCPT + 99 others); Mon, 12 Nov 2018 03:22:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:54174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390806AbeKLIWm (ORCPT ); Mon, 12 Nov 2018 03:22:42 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 51D8322502; Sun, 11 Nov 2018 22:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975565; bh=OlQuWsBZoLHAiuvwcRODMF393XlYXgTxUfg9VQLBNr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fZfjpYF2UASxARmzuZP9K9ANl+6xjgU+4jRCXgj6M/Ya1aH8U+pNsToWZTw57JlYo 5vUHpKvcp3gFQV0LGReXr2RoWFi57xYRahUpNnubtNKF6Ins5oyB4N/c9NF/N5kPEk i6TKMXmev9KJp+JpP1QY4Zpan8EqNNGH91cjn4Rc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+7f4a27091759e2fe7453@syzkaller.appspotmail.com, Lukas Czerner , Jan Kara , Theodore Tso Subject: [PATCH 4.14 135/222] jbd2: fix use after free in jbd2_log_do_checkpoint() Date: Sun, 11 Nov 2018 14:23:52 -0800 Message-Id: <20181111221659.625062178@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit ccd3c4373eacb044eb3832966299d13d2631f66f upstream. The code cleaning transaction's lists of checkpoint buffers has a bug where it increases bh refcount only after releasing journal->j_list_lock. Thus the following race is possible: CPU0 CPU1 jbd2_log_do_checkpoint() jbd2_journal_try_to_free_buffers() __journal_try_to_free_buffer(bh) ... while (transaction->t_checkpoint_io_list) ... if (buffer_locked(bh)) { <-- IO completes now, buffer gets unlocked --> spin_unlock(&journal->j_list_lock); spin_lock(&journal->j_list_lock); __jbd2_journal_remove_checkpoint(jh); spin_unlock(&journal->j_list_lock); try_to_free_buffers(page); get_bh(bh) <-- accesses freed bh Fix the problem by grabbing bh reference before unlocking journal->j_list_lock. Fixes: dc6e8d669cf5 ("jbd2: don't call get_bh() before calling __jbd2_journal_remove_checkpoint()") Fixes: be1158cc615f ("jbd2: fold __process_buffer() into jbd2_log_do_checkpoint()") Reported-by: syzbot+7f4a27091759e2fe7453@syzkaller.appspotmail.com CC: stable@vger.kernel.org Reviewed-by: Lukas Czerner Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/jbd2/checkpoint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/jbd2/checkpoint.c +++ b/fs/jbd2/checkpoint.c @@ -254,8 +254,8 @@ restart: bh = jh2bh(jh); if (buffer_locked(bh)) { - spin_unlock(&journal->j_list_lock); get_bh(bh); + spin_unlock(&journal->j_list_lock); wait_on_buffer(bh); /* the journal_head may have gone by now */ BUFFER_TRACE(bh, "brelse"); @@ -336,8 +336,8 @@ restart2: jh = transaction->t_checkpoint_io_list; bh = jh2bh(jh); if (buffer_locked(bh)) { - spin_unlock(&journal->j_list_lock); get_bh(bh); + spin_unlock(&journal->j_list_lock); wait_on_buffer(bh); /* the journal_head may have gone by now */ BUFFER_TRACE(bh, "brelse");