Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3476609imu; Sun, 11 Nov 2018 16:00:17 -0800 (PST) X-Google-Smtp-Source: AJdET5egK4oPHuJaIAXD4sghK/mbfbAwKBp/uab5j8X3Um9LeuXGd+L8EEgIjsPr2CXUS+vT39Sn X-Received: by 2002:a63:f006:: with SMTP id k6mr15619658pgh.259.1541980817675; Sun, 11 Nov 2018 16:00:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980817; cv=none; d=google.com; s=arc-20160816; b=Z1pYz9Kb+b0I4TxC0kkI+HLMzatLNUibmgXSAi51COLptFBPx+BIN3xm0NWfnKtrdr lzyYNC3kOtOaQFMdh+GQ6CNr7KpsW9HsvE57S/AYcNoko1yHMPvzWQG4yTp7zeSxprm6 nEOwyLGTisMIIZ1qYT7Np/dTZW9hHlrGvCEYPt74Kvm6ndz+it5VdhvjDLE7G04UYrWj 8amjvBVpbFy759U17/fyLrQZwAS29IaMocvRKrF/UMFiIm5nLQ4SWkXRtkxj9tHCEKt1 d2L+PFEVRW6NQbs6HAwGQF5qY8b1g58f4P5EFUmUj0KvH2NVEV3kNEDe6q0VSdRhDLZr 1B7g== 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=Spe+EG15Hi1Tnij0ihrZVURxhpt7Cwj9EcpEKqj3GGc=; b=u4j8vQh/m1jpA5WGOMaedGyL6wkZTsR1ID1vFKXS1vkJlGIXq9URRxCtmc6n5ANQVQ C+G1OyOQy4IaqBk7a53Kb0hNBRF8CMDe+znRKGlT1vCc/FMBMdLRbizdgHS63FFsoOV8 ExQCYCvXat7a/IEEViB8SQU7VixrULd+BOGqq6z2vRSHoqfBqfl+h1Riuf77L18NruVn wtKmQxKc2QI/U4cedKVNs35L2VY/dgZMeNapxF5caq2pF7GxGTP705x4ldefzAu7fbwU qHWsE25dWtWe7UvtASo1BoixUL1J4XqkpiLzzO8UJzwp+loXr6CWQpyNZnI6ZyQ1b4GQ ULQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rfs5mmJO; 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 g21si5046728pgl.114.2018.11.11.16.00.02; Sun, 11 Nov 2018 16:00:17 -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=rfs5mmJO; 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 S1732418AbeKLISG (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:34210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732374AbeKLISD (ORCPT ); Mon, 12 Nov 2018 03:18:03 -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 25087223CA; Sun, 11 Nov 2018 22:28:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975288; bh=T9r4Aju8Og9qwkhWGqQjQYemffWF2QsXI0mWlv+GQqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rfs5mmJOLnB/O/p0FnPTABdhil17J3CissxI0Dfa3/MRdOI6B7z3DtAxZpMwYWhBZ 0e80lkakK/7GwXRBYSmjXwjEivD8ugQ93uXhaXC3IDt0HXZpeEdAYjDYGzUpWBk/yU HU4LPNoMiRds79f7FHAvGzO4OOTpqtgjnuLksJsI= 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.19 224/361] jbd2: fix use after free in jbd2_log_do_checkpoint() Date: Sun, 11 Nov 2018 14:19:31 -0800 Message-Id: <20181111221650.978478600@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -251,8 +251,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"); @@ -333,8 +333,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");