Linux-ext4 Archive on lore.kernel.org
 help / color / Atom feed
From: Jan Kara <jack@suse.cz>
To: Ritesh Harjani <riteshh@linux.ibm.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, jack@suse.cz,
	adilger.kernel@dilger.ca, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] ext4: Unregister sysfs path before destroying jbd2 journal
Date: Wed, 18 Mar 2020 10:13:18 +0100
Message-ID: <20200318091318.GJ22684@quack2.suse.cz> (raw)
In-Reply-To: <20200318061301.4320-1-riteshh@linux.ibm.com>

On Wed 18-03-20 11:43:01, Ritesh Harjani wrote:
> Call ext4_unregister_sysfs(), before destroying jbd2 journal,
> since below might cause, NULL pointer dereference issue.
> This got reported with LTP tests.
> 
> ext4_put_super() 		cat /sys/fs/ext4/loop2/journal_task
> 	| 				ext4_attr_show();
> ext4_jbd2_journal_destroy();  			|
>     	|				 journal_task_show()
> 	| 					|
> 	| 				task_pid_vnr(NULL);
> sbi->s_journal = NULL;
> 
> Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>

Yeah, makes sence. Thanks for the patch! You can add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/super.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 5dc65b7583cb..27ab130a40d1 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1024,6 +1024,13 @@ static void ext4_put_super(struct super_block *sb)
>  
>  	destroy_workqueue(sbi->rsv_conversion_wq);
>  
> +	/*
> +	 * Unregister sysfs before destroying jbd2 journal.
> +	 * Since we could still access attr_journal_task attribute via sysfs
> +	 * path which could have sbi->s_journal->j_task as NULL
> +	 */
> +	ext4_unregister_sysfs(sb);
> +
>  	if (sbi->s_journal) {
>  		aborted = is_journal_aborted(sbi->s_journal);
>  		err = jbd2_journal_destroy(sbi->s_journal);
> @@ -1034,7 +1041,6 @@ static void ext4_put_super(struct super_block *sb)
>  		}
>  	}
>  
> -	ext4_unregister_sysfs(sb);
>  	ext4_es_unregister_shrinker(sbi);
>  	del_timer_sync(&sbi->s_err_report);
>  	ext4_release_system_zone(sb);
> -- 
> 2.21.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-18  6:13 Ritesh Harjani
2020-03-18  9:13 ` Jan Kara [this message]
2020-03-26 14:53   ` Theodore Y. Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200318091318.GJ22684@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=riteshh@linux.ibm.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-ext4 Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-ext4/0 linux-ext4/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-ext4 linux-ext4/ https://lore.kernel.org/linux-ext4 \
		linux-ext4@vger.kernel.org
	public-inbox-index linux-ext4

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-ext4


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git