1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
--- src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcdUnix.cpp.orig 2008-11-09 19:48:22.000000000 +0100
+++ src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcdUnix.cpp 2008-11-09 19:51:54.000000000 +0100
@@ -93,7 +93,7 @@
EOk = 0,
ELockFileOpen = -1,
ELockFileLock = -2,
-
+ ELockFileOwner = -3,
};
static int ipcLockFD = 0;
@@ -112,16 +112,70 @@
lockFile[dirLen] = '/';
memcpy(lockFile + dirLen + 1, lockName, sizeof(lockName));
+#ifdef VBOX
+ //
+ // Security checks for the directory
+ //
+ struct stat st;
+ if (stat(baseDir, &st) == -1)
+ {
+ printf("Cannot stat '%s'.\n", baseDir);
+ return ELockFileOwner;
+ }
+
+ if (st.st_uid != getuid() && st.st_uid != geteuid())
+ {
+ printf("Wrong owner (%d) of '%s'.\n", st.st_uid, baseDir);
+ return ELockFileOwner;
+ }
+
+ if (st.st_mode != (S_IRUSR | S_IWUSR | S_IXUSR | S_IFDIR))
+ {
+ printf("Wrong mode (%o) of '%s'.\n", st.st_mode, baseDir);
+ return ELockFileOwner;
+ }
+#endif
+
//
// open lock file. it remains open until we shutdown.
//
ipcLockFD = open(lockFile, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
+#ifndef VBOX
free(lockFile);
+#endif
if (ipcLockFD == -1)
return ELockFileOpen;
+#ifdef VBOX
+ //
+ // Security checks for the lock file
+ //
+ if (fstat(ipcLockFD, &st) == -1)
+ {
+ printf("Cannot stat '%s'.\n", lockFile);
+ free(lockFile);
+ return ELockFileOwner;
+ }
+
+ if (st.st_uid != getuid() && st.st_uid != geteuid())
+ {
+ printf("Wrong owner (%d) of '%s'.\n", st.st_uid, lockFile);
+ free(lockFile);
+ return ELockFileOwner;
+ }
+
+ if (st.st_mode != (S_IRUSR | S_IWUSR | S_IFREG))
+ {
+ printf("Wrong mode (%o) of '%s'.\n", st.st_mode, lockFile);
+ free(lockFile);
+ return ELockFileOwner;
+ }
+
+ free(lockFile);
+#endif
+
//
// we use fcntl for locking. assumption: filesystem should be local.
// this API is nice because the lock will be automatically released
@@ -433,8 +487,9 @@
// don't notify the parent to cause it to fail in PR_Read() after
// we terminate
#ifdef VBOX
- printf("Cannot create a lock file for '%s'.\n"
- "Check permissions.\n", addr.local.path);
+ if (status != ELockFileOwner)
+ printf("Cannot create a lock file for '%s'.\n"
+ "Check permissions.\n", addr.local.path);
#endif
return 0;
}
|