aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/util.c')
-rw-r--r--src/firejail/util.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c
index 28ad6b990..d6835569d 100644
--- a/src/firejail/util.c
+++ b/src/firejail/util.c
@@ -1037,32 +1037,61 @@ static MountData mdata;
1037// The return value points to a static area, and will be overwritten by subsequent calls. 1037// The return value points to a static area, and will be overwritten by subsequent calls.
1038// The function does an exit(1) if anything goes wrong. 1038// The function does an exit(1) if anything goes wrong.
1039MountData *get_last_mount(void) { 1039MountData *get_last_mount(void) {
1040 // open /proc/self/mounts 1040 // open /proc/self/mountinfo
1041 FILE *fp = fopen("/proc/self/mounts", "r"); 1041 FILE *fp = fopen("/proc/self/mountinfo", "r");
1042 if (!fp) 1042 if (!fp)
1043 goto errexit; 1043 goto errexit;
1044 1044
1045 mbuf[0] = '\0'; 1045 mbuf[0] = '\0';
1046 while (fgets(mbuf, MAX_BUF, fp)); 1046 while (fgets(mbuf, MAX_BUF, fp));
1047 fclose(fp); 1047 fclose(fp);
1048 if (arg_debug || arg_debug_whitelists) 1048 if (arg_debug)
1049 printf("%s", mbuf); 1049 printf("%s", mbuf);
1050 1050
1051 // extract filesystem name and directory 1051 // extract filesystem name, directory and filesystem type
1052 mdata.fsname = mbuf; 1052 // examples:
1053 mdata.dir = strstr(mbuf, " "); 1053 // 587 543 8:1 /tmp /etc rw,relatime master:1 - ext4 /dev/sda1 rw,errors=remount-ro,data=ordered
1054 if (!mdata.dir) 1054 // mdata.fsname: /tmp
1055 // mdata.dir: /etc
1056 // mdata.fstype: ext4
1057 // 585 564 0:76 / /home/netblue/.cache rw,nosuid,nodev - tmpfs tmpfs rw
1058 // mdata.fsname: /
1059 // mdata.dir: /home/netblue/.cache
1060 // mdata.fstype: tmpfs
1061 memset(&mdata, 0, sizeof(mdata));
1062 char *ptr = strtok(mbuf, " ");
1063 if (!ptr)
1055 goto errexit; 1064 goto errexit;
1056 *mdata.dir = '\0'; 1065
1057 mdata.dir++; 1066 int cnt = 1;
1058 char *end = strstr(mdata.dir, " "); 1067 while ((ptr = strtok(NULL, " ")) != NULL) {
1059 if (!end) 1068 cnt++;
1069 if (cnt == 4)
1070 mdata.fsname = ptr;
1071 else if (cnt == 5) {
1072 mdata.dir = ptr;
1073 break;
1074 }
1075 }
1076
1077 ptr = strtok(NULL, "-");
1078 if (!ptr)
1079 goto errexit;
1080
1081 ptr = strtok(NULL, " ");
1082 if (!ptr)
1060 goto errexit; 1083 goto errexit;
1061 *end = '\0'; 1084 mdata.fstype = ptr++;
1062 1085
1086 if (mdata.fsname == NULL ||
1087 mdata.dir == NULL ||
1088 mdata.fstype == NULL)
1089 goto errexit;
1090 if (arg_debug)
1091 printf("fsname=%s dir=%s fstype=%s\n", mdata.fsname, mdata.dir, mdata.fstype);
1063 return &mdata; 1092 return &mdata;
1064 1093
1065errexit: 1094errexit:
1066 fprintf(stderr, "Error: cannot read /proc/self/mounts"); 1095 fprintf(stderr, "Error: cannot read /proc/self/mountinfo\n");
1067 exit(1); 1096 exit(1);
1068} 1097}