checkpath: do not chown or chmod symbolic links
This is another security fix. If you use chown() or chmod() on a symbolic link, it affects the referenced file, not the symbolic link itself. X-Gentoo-Bug: 540006 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=540006
This commit is contained in:
parent
423f82bae9
commit
a0378f3871
@ -68,7 +68,7 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
|
|||||||
int u;
|
int u;
|
||||||
|
|
||||||
memset(&st, 0, sizeof(st));
|
memset(&st, 0, sizeof(st));
|
||||||
if (stat(path, &st) || trunc) {
|
if (lstat(path, &st) || trunc) {
|
||||||
if (type == inode_file) {
|
if (type == inode_file) {
|
||||||
einfo("%s: creating file", path);
|
einfo("%s: creating file", path);
|
||||||
if (!mode) /* 664 */
|
if (!mode) /* 664 */
|
||||||
@ -133,10 +133,14 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mode && (st.st_mode & 0777) != mode) {
|
if (mode && (st.st_mode & 0777) != mode) {
|
||||||
if ((type != inode_dir) && (st.st_nlink != 1)) {
|
if ((type != inode_dir) && (st.st_nlink > 1)) {
|
||||||
eerror("%s: chmod: %s %s", applet, "Too many hard links to", path);
|
eerror("%s: chmod: %s %s", applet, "Too many hard links to", path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (S_ISLNK(st.st_mode)) {
|
||||||
|
eerror("%s: chmod: %s %s", applet, path, " is a symbolic link");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
einfo("%s: correcting mode", path);
|
einfo("%s: correcting mode", path);
|
||||||
if (chmod(path, mode)) {
|
if (chmod(path, mode)) {
|
||||||
eerror("%s: chmod: %s", applet, strerror(errno));
|
eerror("%s: chmod: %s", applet, strerror(errno));
|
||||||
@ -145,10 +149,14 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (chowner && (st.st_uid != uid || st.st_gid != gid)) {
|
if (chowner && (st.st_uid != uid || st.st_gid != gid)) {
|
||||||
if ((type != inode_dir) && (st.st_nlink != 1)) {
|
if ((type != inode_dir) && (st.st_nlink > 1)) {
|
||||||
eerror("%s: chown: %s %s", applet, "Too many hard links to", path);
|
eerror("%s: chown: %s %s", applet, "Too many hard links to", path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (S_ISLNK(st.st_mode)) {
|
||||||
|
eerror("%s: chown: %s %s", applet, path, " is a symbolic link");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
einfo("%s: correcting owner", path);
|
einfo("%s: correcting owner", path);
|
||||||
if (chown(path, uid, gid)) {
|
if (chown(path, uid, gid)) {
|
||||||
eerror("%s: chown: %s", applet, strerror(errno));
|
eerror("%s: chown: %s", applet, strerror(errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user