Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

jfs: makes diUnmount/diMount in jfs_mount_rw atomic

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

Signed-off-by: Oleg Kanatov <okanatov@gmail.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>

authored by

Oleg Kanatov and committed by
Dave Kleikamp
a60dca73 d0e482c4

+5 -1
+1 -1
fs/jfs/jfs_imap.c
··· 310 310 iagno = INOTOIAG(ip->i_ino); 311 311 312 312 /* read the iag */ 313 - imap = JFS_IP(ipimap)->i_imap; 314 313 IREAD_LOCK(ipimap, RDWRLOCK_IMAP); 314 + imap = JFS_IP(ipimap)->i_imap; 315 315 rc = diIAGRead(imap, iagno, &mp); 316 316 IREAD_UNLOCK(ipimap); 317 317 if (rc) {
+4
fs/jfs/jfs_mount.c
··· 234 234 235 235 truncate_inode_pages(sbi->ipimap->i_mapping, 0); 236 236 truncate_inode_pages(sbi->ipbmap->i_mapping, 0); 237 + 238 + IWRITE_LOCK(sbi->ipimap, RDWRLOCK_IMAP); 237 239 diUnmount(sbi->ipimap, 1); 238 240 if ((rc = diMount(sbi->ipimap))) { 241 + IWRITE_UNLOCK(sbi->ipimap); 239 242 jfs_err("jfs_mount_rw: diMount failed!"); 240 243 return rc; 241 244 } 245 + IWRITE_UNLOCK(sbi->ipimap); 242 246 243 247 dbUnmount(sbi->ipbmap, 1); 244 248 if ((rc = dbMount(sbi->ipbmap))) {