Received: by 10.192.165.148 with SMTP id m20csp829533imm; Fri, 27 Apr 2018 08:10:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZraUA5rMnWAdwbhbPfh95STrreYf52wYDPxjOAzwfj/rOFTEdJKYbMirJ53O3Zg6mkAmuwK X-Received: by 2002:a63:77ce:: with SMTP id s197-v6mr2414027pgc.272.1524841802768; Fri, 27 Apr 2018 08:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524841802; cv=none; d=google.com; s=arc-20160816; b=mGdwpOrNsT24Hk+vshbuzLbH5nOUIhJBqz8WR5MA3NZycV99ZUvdB2HM3IjM/xyK+X fKRpgfNQ/bB5v85C0go2UxNLuGvyCb/Wi8JDrIMJMTMFH8cKw/N0ym9wyhJV3k3NDUx8 VaMox9RTPX6n6A7q7TcCC7iUOE6s7h2pbAKFuAVGslytpVdr3fe6xRBjnahZyPv28R70 Ee0uQG3fXvKUGKC9n8lIdBKy8TPv50h14dRSMJGj+ovSBJC8TnjnXaUT+vMyOtjKYhlM yo1H7lkzl+ZlhlWsE8lA9wZkAFhU+Kw66lUAr81yDRsjKiq7yuE/5qW4zikym8QhKPtU HzgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=EEue0m76upYZ6907Fu+N4ScTwbuJBRln68CRF/jRY9g=; b=j9x04TaWBPULFVTC2qlUJ3iUzuNIhO2M0mbghkh1+V/e2RVssl0l2Gtc9ZvFv07TYO OcNPN6N/MkhTdJlRfI90Rq1SNJY2Ru/cBUkQJFbEELmnnDhv3G2HD1ng3PrGHsrqgJN/ GFvJzLOn5CzUayK5jun2+iwktwWsSlJKQq9/CDI0TqYcAgZ3sH0BpEyeNthWkIV2lDox GYCKh4s+yTvbqxHIyDdzAqtneub4LGfKL+8z7bbrdjoM+qWZIQ0RRnZ32RTrWgERldBH oM4d+JkulSrVYGCZGzeHBjbaDVHrQ3HDpRiLohHOBdgXkA9ZjJdPR0/GDsU81NrwXNUK eq+Q== ARC-Authentication-Results: i=1; mx.google.com; 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 d14si1364524pfl.122.2018.04.27.08.09.47; Fri, 27 Apr 2018 08:10:02 -0700 (PDT) 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; 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 S933880AbeD0PHY (ORCPT + 99 others); Fri, 27 Apr 2018 11:07:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:50950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933740AbeD0OEj (ORCPT ); Fri, 27 Apr 2018 10:04:39 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 7081421890; Fri, 27 Apr 2018 14:04:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7081421890 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sahitya Tummala , Theodore Tso , Amit Pundir Subject: [PATCH 4.9 17/74] jbd2: fix use after free in kjournald2() Date: Fri, 27 Apr 2018 15:58:07 +0200 Message-Id: <20180427135710.616430102@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135709.899303463@linuxfoundation.org> References: <20180427135709.899303463@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sahitya Tummala commit dbfcef6b0f4012c57bc0b6e0e660d5ed12a5eaed upstream. Below is the synchronization issue between unmount and kjournald2 contexts, which results into use after free issue in kjournald2(). Fix this issue by using journal->j_state_lock to synchronize the wait_event() done in journal_kill_thread() and the wake_up() done in kjournald2(). TASK 1: umount cmd: |--jbd2_journal_destroy() { |--journal_kill_thread() { write_lock(&journal->j_state_lock); journal->j_flags |= JBD2_UNMOUNT; ... write_unlock(&journal->j_state_lock); wake_up(&journal->j_wait_commit); TASK 2 wakes up here: kjournald2() { ... checks JBD2_UNMOUNT flag and calls goto end-loop; ... end_loop: write_unlock(&journal->j_state_lock); journal->j_task = NULL; --> If this thread gets pre-empted here, then TASK 1 wait_event will exit even before this thread is completely done. wait_event(journal->j_wait_done_commit, journal->j_task == NULL); ... write_lock(&journal->j_state_lock); write_unlock(&journal->j_state_lock); } |--kfree(journal); } } wake_up(&journal->j_wait_done_commit); --> this step now results into use after free issue. } Signed-off-by: Sahitya Tummala Signed-off-by: Theodore Ts'o Cc: Amit Pundir Signed-off-by: Greg Kroah-Hartman --- fs/jbd2/journal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -276,11 +276,11 @@ loop: goto loop; end_loop: - write_unlock(&journal->j_state_lock); del_timer_sync(&journal->j_commit_timer); journal->j_task = NULL; wake_up(&journal->j_wait_done_commit); jbd_debug(1, "Journal thread exiting.\n"); + write_unlock(&journal->j_state_lock); return 0; }