pseudo: Fix openat() with a symlink pointing to a directory
PATCH v3 1/1 pseudo: Fix openat() with a symlink pointing to a directory
While working with ostree disk generation in conjunction with wic, I found a problem with pseudo where it tried to resolve a symlink when it shouldn't, based on openat() flags. A C program has been constructed to test pseudo to show that it is working properly with the correct behavior around openat().
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
/*
* Tested with: gcc -Wall -o app app.c ; echo "no pseudo" ;
* ./app ; echo "pseudo"; pseudo ./app
*/
system("rm -rf tdir tlink");
system("mkdir tdir");
system("ln -s tdir tlink");
DIR *dir = opendir(".");
int dfd = dirfd(dir);
int target_dfd = openat (dfd, "tlink", O_RDONLY | O_NONBLOCK |
O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (target_dfd == -1) {
printf("Test 1 good\n");
} else {
printf("Test 1 failed\n");
close(target_dfd);
}
target_dfd = openat (dfd, "tlink", O_RDONLY | O_NONBLOCK |
O_DIRECTORY | O_CLOEXEC);
if (target_dfd == -1) {
printf("Test 2 failed\n");
} else {
printf("Test 2 good\n");
close(target_dfd);
}
/* Test 3 make sure the owner of the link is root */
struct stat sbuf;
if (!lstat("tlink", &sbuf) && sbuf.st_uid == 0) {
printf("Test 3 good\n");
} else {
printf("Test 3 failed\n");
}
/* Test 4 tests open with the "rb" flag, owner should not change */
int ofd = openat(dfd,"./tlink", O_RDONLY|O_CLOEXEC);
if (ofd >= 0) {
if (fstat(ofd, &sbuf) != 0)
printf("ERROR in fstat test 4\n");
else if (sbuf.st_uid == 0)
printf("Test 4 good\n");
close(ofd);
} else {
printf("Test 4 failed with openat()\n");
}
/* Test pseudo db to see the fstat() above did not delete the DB entry */
if (!lstat("tlink", &sbuf) && sbuf.st_uid == 0)
printf("Test 5 good\n");
else
printf("Test 5 failed... tlink is owned by %i and not 0\n", sbuf.st_uid);
return 0;
}int main()
{
/* Tested with: gcc -Wall -o app app.c ; echo "no pseudo" ; ./app ; echo "pseudo"; pseudo ./app */
system("rm -rf tdir tlink");
system("mkdir tdir");
system("ln -s tdir tlink");
DIR *dir = opendir(".");
int dfd = dirfd(dir);
int target_dfd = openat (dfd, "tlink", O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (target_dfd == -1) {
printf("This is right\n");
} else {
printf("This is broken\n");
}
return 0;
}Many thanks to Peter Seebach for fixing the problem in the pseudo code to use the same logic which was already there for the AT_SYMLINK_NOFOLLOW.
Also updated is the license MD5 checksum since the master branch of pseudo has had the SPDX data updated.
--- meta/recipes-devtools/pseudo/pseudo.inc | 2 +- meta/recipes-devtools/pseudo/pseudo_git.bb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
meta/recipes-devtools/pseudo/pseudo.inc +1 -1
@@ -4,7 +4,7 @@ SUMMARY = "Pseudo gives fake root capabilities to a normal user" HOMEPAGE = "http://git.yoctoproject.org/cgit/cgit.cgi/pseudo" -LIC_FILES_CHKSUM = "file://COPYING;md5=243b725d71bb5df4a1e5920b344b86ad" +LIC_FILES_CHKSUM = "file://COPYING;md5=a1d8023a6f953ac6ea4af765ff62d574" SECTION = "base" LICENSE = "LGPL2.1" DEPENDS = "sqlite3 attr"
meta/recipes-devtools/pseudo/pseudo_git.bb +1 -1
@@ -8,7 +8,7 @@ SRC_URI = "git://git.yoctoproject.org/pseudo \ file://toomanyfiles.patch \ " -SRCREV = "3fa7c853e0bcd6fe23f7524c2a3c9e3af90901c3" +SRCREV = "060058bb29f70b244e685b3c704eb0641b736f73" S = "${WORKDIR}/git" PV = "1.9.0+git${SRCPV}"
Signature · 1 line
2.21.0
Quoted 6 lines · Jason Wessel
While working with ostree disk generation in conjunction with wic, I found a problem with pseudo where it tried to resolve a symlink when it shouldn't, based on
openat()flags. A C program has been constructed to test pseudo to show that it is working properly with the correct behavior aroundopenat().
[...]
Quoted 6 lines
Many thanks to Peter Seebach for fixing the problem in the pseudo code
to use the same logic which was already there for theAT_SYMLINK_NOFOLLOW.
Quoted 8 lines
Also updated is the license MD5 checksum since the master branch of pseudo has had the SPDX data updated.
Signed-off-by Jason Wessel <[email protected]>--- meta/recipes-devtools/pseudo/pseudo.inc | 2 +- meta/recipes-devtools/pseudo/pseudo_git.bb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
pseudo-native didn't build on fedora28 or centos7:
(see the pseudo-native failures).
It looks like an issue on hosts which don't have zlib-devel installed, at a very approximate guess - I've not been able to look in detail.
Cheers,
Richard
Quoted 25 lines · Richard Purdie
Quoted 6 lines · Jason Wessel
While working with ostree disk generation in conjunction with wic, I found a problem with pseudo where it tried to resolve a symlink when it shouldn't, based on
openat()flags. A C program has been constructed to test pseudo to show that it is working properly with the correct behavior aroundopenat().[...]
Quoted 6 lines
Many thanks to Peter Seebach for fixing the problem in the pseudo code
to use the same logic which was already there for theAT_SYMLINK_NOFOLLOW.Quoted 8 lines
Also updated is the license MD5 checksum since the master branch of pseudo has had the SPDX data updated.
Signed-off-by Jason Wessel <[email protected]>--- meta/recipes-devtools/pseudo/pseudo.inc | 2 +- meta/recipes-devtools/pseudo/pseudo_git.bb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)pseudo-native didn't build on fedora28 or centos7:
Quoted 8 lines
(see the pseudo-native failures).
It looks like an issue on hosts which don't have zlib-devel installed,
at a very approximate guess - I've not been able to look in detail.
I'll try and setup a test, since I can easily run fedora28. I wonder if we can just use zlib-native to solve it, or if it is a a chicken-egg problem with the early boot strap.
Jason.
Quoted 28 lines · Jason Wessel
Quoted 27 lines · Richard Purdie
Quoted 6 lines · Jason Wessel
While working with ostree disk generation in conjunction with wic, I found a problem with pseudo where it tried to resolve a symlink when it shouldn't, based on
openat()flags. A C program has been constructed to test pseudo to show that it is working properly with the correct behavior aroundopenat().[...]
Quoted 6 lines
Many thanks to Peter Seebach for fixing the problem in the pseudo code
to use the same logic which was already there for theAT_SYMLINK_NOFOLLOW.Quoted 8 lines
Also updated is the license MD5 checksum since the master branch of pseudo has had the SPDX data updated.
Signed-off-by Jason Wessel <[email protected]>--- meta/recipes-devtools/pseudo/pseudo.inc | 2 +- meta/recipes-devtools/pseudo/pseudo_git.bb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)pseudo-native didn't build on fedora28 or centos7:
Quoted 9 lines
Quoted 6 lines
(see the pseudo-native failures).
It looks like an issue on hosts which don't have zlib-devel installed,
at a very approximate guess - I've not been able to look in detail.
I'll try and setup a test, since I can easily run fedora28. I wonder if we can just use zlib-native to solve it, or if it is a a chicken-egg problem with the early boot strap.
I cannot duplicate the problem. It must have to do with the way your particular system is setup. What is interesting is that the -lz is not actually called on my system, where I most certainly don't have the libz devel package installed. I am guessing there is a configure failure of some sort?
Do you think on the fedora28 system you could send me the "rpm -q -a" output?
Jason.
Quoted 36 lines · Jason Wessel
Quoted 35 lines · Jason Wessel
Quoted 33 lines · Richard Purdie
Quoted 6 lines · Jason Wessel
While working with ostree disk generation in conjunction with wic, I found a problem with pseudo where it tried to resolve a symlink when it shouldn't, based on
openat()flags. A C program has been constructed to test pseudo to show that it is working properly with the correct behavior aroundopenat().[...]
Quoted 6 lines
Many thanks to Peter Seebach for fixing the problem in the pseudo code
to use the same logic which was already there for theAT_SYMLINK_NOFOLLOW.Quoted 8 lines
Also updated is the license MD5 checksum since the master branch of pseudo has had the SPDX data updated.
Signed-off-by Jason Wessel <[email protected]>--- meta/recipes-devtools/pseudo/pseudo.inc | 2 +- meta/recipes-devtools/pseudo/pseudo_git.bb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)pseudo-native didn't build on fedora28 or centos7:
(see the pseudo-native failures).
It looks like an issue on hosts which don't have zlib-devel installed,
at a very approximate guess - I've not been able to look in detail.
Quoted 7 lines
Quoted 2 lines
I'll try and setup a test, since I can easily run fedora28. I wonder if we can just use zlib-native to solve it, or if it is a a chicken-egg problem with the early boot strap.
I cannot duplicate the problem. It must have to do with the way your particular system is setup. What is interesting is that the -lz is not actually called on my system, where I most certainly don't have the libz devel package installed. I am guessing there is a configure failure of some sort?
Do you think on the fedora28 system you could send me the "rpm -q -a" output?
I found out where the link flags come from in the pseudo recipe.
for sqlite_link_opt in $(pkg-config sqlite3 --libs --static)
do
case "$sqlite_link_opt" in
-lsqlite3)
;;
-l*)
SQLITE_LDADD="${SQLITE_LDADD} ${sqlite_link_opt}"This implies that your local sqlite3 is perhaps different in some manner. I am not sure exactly what kind of edge case you have going on with your system. :-)
Cheers,
Jason.