linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] jfs: makes diUnmount/diMount in jfs_mount_rw atomic
@ 2022-10-28 12:22 Oleg Kanatov
  2022-11-10 21:47 ` Dave Kleikamp
  0 siblings, 1 reply; 2+ messages in thread
From: Oleg Kanatov @ 2022-10-28 12:22 UTC (permalink / raw)
  To: Dave Kleikamp
  Cc: Oleg Kanatov, jfs-discussion, linux-kernel, lvc-project, Oleg Kanatov

jfs_mount_rw can call diUnmount and then diMount. These calls
change the imap pointer.
In case JFS filesystem is mounted on root (/), between these two
calls there may be calls of function jfs_lookup().
The jfs_lookup() function calls jfs_iget(), which, in its turn,
calls diRead(). The latter references the imap pointer.
That may cause diRead() to refer to a pointer "freed" in
diUnmount().
This commit makes calls diUnmount()/diMount() be atomic so that
nothing will read the imap pointer until the whole remount is
completed.

Signed-off-by: Oleg Kanatov <okanatov@gmail.com>
---
 fs/jfs/jfs_imap.c  | 2 +-
 fs/jfs/jfs_mount.c | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
index 799d3837e7c2..390cbfce391f 100644
--- a/fs/jfs/jfs_imap.c
+++ b/fs/jfs/jfs_imap.c
@@ -310,8 +310,8 @@ int diRead(struct inode *ip)
 	iagno = INOTOIAG(ip->i_ino);
 
 	/* read the iag */
-	imap = JFS_IP(ipimap)->i_imap;
 	IREAD_LOCK(ipimap, RDWRLOCK_IMAP);
+	imap = JFS_IP(ipimap)->i_imap;
 	rc = diIAGRead(imap, iagno, &mp);
 	IREAD_UNLOCK(ipimap);
 	if (rc) {
diff --git a/fs/jfs/jfs_mount.c b/fs/jfs/jfs_mount.c
index 48d1f70f786c..972b9ff18723 100644
--- a/fs/jfs/jfs_mount.c
+++ b/fs/jfs/jfs_mount.c
@@ -234,12 +234,18 @@ int jfs_mount_rw(struct super_block *sb, int remount)
 
 		truncate_inode_pages(sbi->ipimap->i_mapping, 0);
 		truncate_inode_pages(sbi->ipbmap->i_mapping, 0);
+
+		IWRITE_LOCK(sbi->ipimap, RDWRLOCK_IMAP);
+
 		diUnmount(sbi->ipimap, 1);
 		if ((rc = diMount(sbi->ipimap))) {
+			IWRITE_UNLOCK(sbi->ipimap);
 			jfs_err("jfs_mount_rw: diMount failed!");
 			return rc;
 		}
 
+		IWRITE_UNLOCK(sbi->ipimap);
+
 		dbUnmount(sbi->ipbmap, 1);
 		if ((rc = dbMount(sbi->ipbmap))) {
 			jfs_err("jfs_mount_rw: dbMount failed!");
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] jfs: makes diUnmount/diMount in jfs_mount_rw atomic
  2022-10-28 12:22 [PATCH] jfs: makes diUnmount/diMount in jfs_mount_rw atomic Oleg Kanatov
@ 2022-11-10 21:47 ` Dave Kleikamp
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Kleikamp @ 2022-11-10 21:47 UTC (permalink / raw)
  To: Oleg Kanatov; +Cc: Oleg Kanatov, jfs-discussion, linux-kernel, lvc-project

Applied with trivial changes. I cleaned up the commit message a little 
and removed a couple blank lines.

Thanks!

On 10/28/22 7:22AM, Oleg Kanatov wrote:
> jfs_mount_rw can call diUnmount and then diMount. These calls
> change the imap pointer.
> In case JFS filesystem is mounted on root (/), between these two
> calls there may be calls of function jfs_lookup().
> The jfs_lookup() function calls jfs_iget(), which, in its turn,
> calls diRead(). The latter references the imap pointer.
> That may cause diRead() to refer to a pointer "freed" in
> diUnmount().
> This commit makes calls diUnmount()/diMount() be atomic so that
> nothing will read the imap pointer until the whole remount is
> completed.
> 
> Signed-off-by: Oleg Kanatov <okanatov@gmail.com>
> ---
>   fs/jfs/jfs_imap.c  | 2 +-
>   fs/jfs/jfs_mount.c | 6 ++++++
>   2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
> index 799d3837e7c2..390cbfce391f 100644
> --- a/fs/jfs/jfs_imap.c
> +++ b/fs/jfs/jfs_imap.c
> @@ -310,8 +310,8 @@ int diRead(struct inode *ip)
>   	iagno = INOTOIAG(ip->i_ino);
>   
>   	/* read the iag */
> -	imap = JFS_IP(ipimap)->i_imap;
>   	IREAD_LOCK(ipimap, RDWRLOCK_IMAP);
> +	imap = JFS_IP(ipimap)->i_imap;
>   	rc = diIAGRead(imap, iagno, &mp);
>   	IREAD_UNLOCK(ipimap);
>   	if (rc) {
> diff --git a/fs/jfs/jfs_mount.c b/fs/jfs/jfs_mount.c
> index 48d1f70f786c..972b9ff18723 100644
> --- a/fs/jfs/jfs_mount.c
> +++ b/fs/jfs/jfs_mount.c
> @@ -234,12 +234,18 @@ int jfs_mount_rw(struct super_block *sb, int remount)
>   
>   		truncate_inode_pages(sbi->ipimap->i_mapping, 0);
>   		truncate_inode_pages(sbi->ipbmap->i_mapping, 0);
> +
> +		IWRITE_LOCK(sbi->ipimap, RDWRLOCK_IMAP);
> +
>   		diUnmount(sbi->ipimap, 1);
>   		if ((rc = diMount(sbi->ipimap))) {
> +			IWRITE_UNLOCK(sbi->ipimap);
>   			jfs_err("jfs_mount_rw: diMount failed!");
>   			return rc;
>   		}
>   
> +		IWRITE_UNLOCK(sbi->ipimap);
> +
>   		dbUnmount(sbi->ipbmap, 1);
>   		if ((rc = dbMount(sbi->ipbmap))) {
>   			jfs_err("jfs_mount_rw: dbMount failed!");

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-10 21:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-28 12:22 [PATCH] jfs: makes diUnmount/diMount in jfs_mount_rw atomic Oleg Kanatov
2022-11-10 21:47 ` Dave Kleikamp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).