public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
Cc: ltp-list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH] lib/tst_uid_gid.c: fix checking return value errors about getpwuid_r/getgrgid_r
Date: Tue, 8 Apr 2014 17:52:52 +0200	[thread overview]
Message-ID: <20140408155251.GA3201@rei> (raw)
In-Reply-To: <20140408144954.GA1841@rei>

Hi!
> Hmm, as far as I can see the the error for bin.gr_gid is EPERM, while
> invalid user test expect EINVAL, so something must be different.
> 
> And it looks like you can really get EINVAL in the setregid() in
> kernel/sys.c. And that it depends on namespace mappings. See
> kernel/user_namespace.c make_kgid() that calls map_id_down(), although I
> haven't yet figured out exact conditions yet.

And here is the rest of the story.

Unless process modified it's user namespace the get_current_ns() will
return pointer to init_user_ns that is defined in kernel/user.c. This
user namespace maps gids and uids 1:1 in the interval 0 - 4294967294.
Because if I understand the code right the map_id_down checks if id is
in interval between first and first + count - 1 and the count is set to
4294967295. The 4294967295 on the other hand equals to (u32)-1 which is
not included in the mapping but this is the value used for error exit so
it maps uids and gids 1:1 by default.


I've looked closely at the setregid() syscall code and I'm pretty sure
that you can't get EINVAL unless you played with namespaces. Looking
closely at the setregid02 testcase the test is wrong see closely these
lines:


                                if (TEST_ERRNO == test_data[i].exp_errno) {
                                        tst_resm(TPASS, "setregid(%d, %d) "
                                                 "failed as expected.",
                                                 *test_data[i].real_gid,
                                                 *test_data[i].eff_gid);
                                } else if (TEST_ERRNO == test_data[0].exp_errno) {
                                        tst_resm(TPASS, "setregid(%d, %d) "
                                                 "failed as expected.",
                                                 *test_data[i].real_gid,
                                                 *test_data[i].eff_gid);
                                } else {
                                        tst_resm(TFAIL, "setregid(%d, %d) "
                                                 "failed (%d) but did not set the "
                                                 "expected errno (%d).",
                                                 *test_data[i].real_gid,
                                                 *test_data[i].eff_gid,
                                                 TEST_ERRNO,
                                                 test_data[i].exp_errno);
                                }


The test allows the call to faile with either it's expected errno or with the
expected errno of the first testcase. This looks like ugly workaround for some
kernel changes.

The git log says:

    Correct testcase return on RHEL 3 & 4 2.6.13-rc6-mm1

So the best solution would be to remove this workaround and the two testcases
as well.


The setresuid() is the same, it cannot return EINVAL unless namespaces were
involved namespaces were modified. I would go for removing the redundant
testcases there as well.

Uff, that's it, to sum it up, I would go for removing the testcase that employs
GET_INVALID* got rid of the tst_ functions as well. Sorry that I didn't get it
right the first time.


PS: The codepath looks like it can return ENOMEM. I wonder if we can get it
    if we play with process ulimits.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2014-04-08 15:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-20  2:10 [LTP] [PATCH] lib/tst_uid_gid.c: fix checking return value errors about getpwuid_r/getgrgid_r Zeng Linggang
2014-02-20  7:53 ` Stanislav Kholmanskikh
2014-03-06 11:34   ` Zeng Linggang
2014-03-06 12:36     ` Stanislav Kholmanskikh
2014-03-10  8:13       ` Zeng Linggang
2014-03-13  8:33 ` Zeng Linggang
     [not found] ` <1396944482.2100.1.camel@G08JYZSD130126>
2014-04-08 11:19   ` chrubis
     [not found]     ` <5344069B.8010101@oracle.com>
2014-04-08 14:49       ` chrubis
2014-04-08 15:52         ` chrubis [this message]
     [not found]           ` <5344E5C8.3070306@oracle.com>
2014-04-09 13:08             ` chrubis
     [not found]               ` <53454939.2030704@oracle.com>
2014-04-09 13:23                 ` chrubis
2014-04-09 14:39                   ` chrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140408155251.GA3201@rei \
    --to=chrubis@suse.cz \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=stanislav.kholmanskikh@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox