Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1571263

Re: [PATCH] jbd2: Fix use after free in kjournald2()

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From "Tummala, Sahitya" <stummala@codeaurora.org>
Newsgroups linux.kernel
Subject Re: [PATCH] jbd2: Fix use after free in kjournald2()
Date Wed, 01 Feb 2017 05:30:01 +0100
Message-ID <t5UIp-1aG-1@gated-at.bofh.it> (permalink)
References <t5HUS-1S1-29@gated-at.bofh.it> <t5J0C-2tO-31@gated-at.bofh.it>
X-Original-To Jan Kara <jack@suse.cz>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1485922967; bh=F1dIDcSkDaEVVn2fB4HcgStmCsfI5OgoNmPdfoLS66M=; h=Subject:To:References:Cc:From:Date:In-Reply-To:From; b=X54rnQCX7YK7CYU1vUUrQ5e9HuAQet+06qhSp2/USXl2dSF8xY+9ZeLbbCs5dVk1y wY3unZppo+Lr/MOgD2z6mmw9urYHod4Kief7siyURLzCoh7noX1WzS2wV7VlvfauFb jkRZ65GFNU/C1aL+uHsSEEvq7Vzt6HZf6n+vFm94=
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1485922966; bh=F1dIDcSkDaEVVn2fB4HcgStmCsfI5OgoNmPdfoLS66M=; h=Subject:To:References:Cc:From:Date:In-Reply-To:From; b=RRq6yqv6kOcBnFIqIQS2BzQ06MO7Cz6VsfR4cYZvbvM5B73g1AlBbcZpNACgdyMLr dn7LlgdRYtaJ++bZIB3PJJjpdOym1UzZvCYefoc/D81Wn3tuXXeRhJuIHYk3QKTgC9 EWUrzKkZpQ6CN7UJ+XAv7LCZ8K192a60v7KVll5A=
Dmarc-Filter OpenDMARC Filter v1.3.2 smtp.codeaurora.org A474D60290
Authentication-Results pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org
Authentication-Results pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=stummala@codeaurora.org
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0
MIME-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 76
Organization linux.* mail to news gateway
X-Original-Cc Theodore Ts'o <tytso@mit.edu>, Jan Kara <jack@suse.com>, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
X-Original-Date Wed, 1 Feb 2017 09:52:41 +0530
X-Original-Message-ID <5c4bcc82-386a-a8b1-a752-42ec89446df4@codeaurora.org>
X-Original-References <1485873537-32514-1-git-send-email-stummala@codeaurora.org> <20170131155155.GC15249@quack2.suse.cz>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1571263

Show key headers only | View raw


On 1/31/2017 9:21 PM, Jan Kara wrote:
> On Tue 31-01-17 20:08:57, Sahitya Tummala wrote:
>> 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 <stummala@codeaurora.org>
> Yeah, what you write looks possible (although rather unlikely). Thanks for
> catching this. One small nit below:
Yes, it was observed only once and is very hard to reproduce.
>> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
>> index a097048..f5cd3c0 100644
>> --- a/fs/jbd2/journal.c
>> +++ b/fs/jbd2/journal.c
>> @@ -278,9 +278,11 @@ static int kjournald2(void *arg)
>>   end_loop:
>>   	write_unlock(&journal->j_state_lock);
>>   	del_timer_sync(&journal->j_commit_timer);
>> +	write_lock(&journal->j_state_lock);
> There's no good reason to do del_timer_sync() outside of j_state_lock. This
> is not performance critical code and commit_timeout is trivial and cannot
> block on anything. So just keep j_state_lock locked upto the place where
> you unlock it now...
>
Sure, I will update the patch.
> 								Honza
>>   	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;
>>   }
>>   
>> -- 
>> Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
>>
>>

-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[PATCH] jbd2: Fix use after free in kjournald2() Sahitya Tummala <stummala@codeaurora.org> - 2017-01-31 15:50 +0100
  Re: [PATCH] jbd2: Fix use after free in kjournald2() Jan Kara <jack@suse.cz> - 2017-01-31 17:00 +0100
    Re: [PATCH] jbd2: Fix use after free in kjournald2() "Tummala, Sahitya" <stummala@codeaurora.org> - 2017-02-01 05:30 +0100

csiph-web