Files
poky/meta/recipes-devtools
Jason Wessel 6cac15e514 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.

(From OE-Core rev: a98ea4be5ce19ff380ca500ba1ef3da490ec4556)

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-08-07 16:08:15 +01:00
..
2019-06-30 22:40:52 +01:00
2019-07-02 08:13:07 +01:00
2019-06-01 11:27:07 +01:00
2019-06-27 12:20:35 +01:00
2018-08-23 18:02:23 +01:00
2019-04-26 10:09:08 +01:00
2019-06-30 22:40:52 +01:00
2018-03-06 06:43:10 -08:00
2019-05-29 12:54:12 +01:00
2019-07-18 12:16:19 +01:00
2018-11-14 11:14:39 +00:00
2018-03-09 09:17:03 -08:00
2019-04-16 11:10:02 +01:00
2019-07-31 23:03:01 +01:00
2019-07-10 09:56:22 +01:00
2019-04-03 14:50:13 +01:00
2019-05-27 17:06:34 +01:00
2018-01-30 12:53:16 +00:00
2019-02-15 16:05:37 +00:00
2019-05-16 09:16:50 +01:00
2019-07-31 23:03:01 +01:00
2019-05-08 23:00:32 +01:00
2019-07-17 19:25:02 +01:00
2019-07-15 09:30:00 +01:00
2019-04-23 23:30:19 +01:00
2019-07-31 23:03:01 +01:00
2019-05-08 12:15:17 +01:00
2019-07-31 23:03:01 +01:00
2019-07-18 12:16:19 +01:00
2018-11-14 11:14:39 +00:00
2019-08-03 23:56:01 +01:00
2019-08-06 11:24:27 +01:00
2019-07-02 08:13:07 +01:00
2019-07-19 16:19:14 +01:00
2019-07-02 08:13:07 +01:00
2019-07-26 08:41:38 +01:00
2019-03-04 22:57:05 +00:00
2019-06-20 13:14:21 +01:00
2019-04-05 17:32:50 +01:00