0

I'm trying to get devt of mountpoint (path*) in one of the LSM hooks. Assuming I have the following mount:

/dev/mmcblk0p5 is mounted to /mnt/photos

I would expect that calling

kern_path("/mnt/photos", ...)

will return a struct path with path.mnt->mnt_sb->s_dev = 0x0b300005 since /dev/mmcblk0p5 is 179:5, but I always get 0x0b300002 (i.e. 179:2) - which is the root-fs device. Only after mounting again /dev/mmcblk0p5 to /mnt/photos, kern_path returns 0x0b300005.

Why is that? How can I fix it?
It happens with both kernel 4.14 and 5.15.

some more info, after 1st mount, printing address of path.mnt->mnt_sb is the same as of "/" (0x0b300002). after 2nd mount, printing address of path.mnt->mnt_sb is different. i guess that mnt_sb is being updated sometime between the 1st and the 2nd mount. so, when it happens? how can i get notification/hook after this update?

Dekel N
  • 1
  • 1
  • I fixed the second hexa value because you put 0x0b300005 twice... – Rachid K. May 14 '23 at 12:39
  • Can you show the mount commands that you are using? I guess that /mnt is on the rootfs (located in /dev/mmcblk0p2). But what, about the subdirectory photos? Is it in the rootfs (/dev/mmcblk0p2) or in /dev/mmcblk0p5? – Rachid K. May 14 '23 at 13:10
  • mount command: sudo mount /dev/mmcblk0p5 /mnt/photos. in case i do umount, and then mount, i get 0x0b300002. then, if i do mount again (without umount), i get 0x0b300005 as expected. it seems like the /mnt/photos is not completely mounted on 1st time. i tried to call kern_path in several LSM hooks (sb_mount, sb_kern_mount, ...) but this problem happens in all of them. – Dekel N May 15 '23 at 06:18

0 Answers0