linux-test-project / ltp

Linux Test Project (mailing list: https://lists.linux.it/listinfo/ltp)
https://linux-test-project.readthedocs.io/
GNU General Public License v2.0
2.27k stars 1k forks source link

One of the mq_unlink01 testcase is failing #1092

Open Mona-Bagare opened 8 months ago

Mona-Bagare commented 8 months ago

In testcase 1:

void setup(void)
{
    euid = geteuid();
    pw = SAFE_GETPWNAM("nobody");
}
static void do_test(unsigned int i)
{
    struct test_case *tc = &tcase[i];
    mqd_t fd;

    tst_res(TINFO, "queue name %s", tc->qname);

    /*
     * When test ended with SIGTERM etc, mq descriptor is left remains.
     * So we delete it first.
     */
    mq_unlink(QUEUE_NAME);

    /* prepare */
    fd = SAFE_MQ_OPEN(QUEUE_NAME, O_CREAT | O_EXCL | O_RDWR, S_IRWXU, NULL);

    if (tc->as_nobody && seteuid(pw->pw_uid)) {
        tst_res(TFAIL | TERRNO, "seteuid failed");
        goto EXIT;
    }

seteuid(pw->pw_uid) is supposed to change the owner to "nobody", but still "root" is executing as owner and as a result testcase is failing. Below is the snapshot of execution record:

tst.c:1558: TINFO: Timeout per run is 0h 20m 00s mq_unlink01.c:76: TINFO: queue name /test_mqueue mq_unlink01.c:99: TPASS: mq_unlink returned 0: SUCCESS (0) mq_unlink01.c:76: TINFO: queue name /test_mqueue mq_unlink01.c:95: TFAIL: mq_unlink returned 0, expected -1, expected errno EACCES (13): SUCCESS (0) mq_unlink01.c:76: TINFO: queue name /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa mq_unlink01.c:99: TPASS: mq_unlink returned -1: ENOENT (2) mq_unlink01.c:76: TINFO: queue name /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa mq_unlink01.c:99: TPASS: mq_unlink returned -1: ENAMETOOLONG (36) Summary: passed 3 failed 1 broken 0 skipped 0 warnings 0 <<>> initiation_status="ok" duration=0 termination_type=exited termination_id=1 corefile=no cutime=0 cstime=0 <<>> INFO: ltp-pan reported some tests FAIL LTP Version: 20230127

Please suggest the solution

Martchus commented 8 months ago

I can't reproduce the problem on my Tumbleweed system.

seteuid(pw->pw_uid) is supposed to change the owner to "nobody"

This call is supposed to change the effective user to "nobody". This should provoke an access error when trying to unlink the message queue that is still owned by root (although maybe the permissions/ownership of the parent directory might be relevant as well).