From: Jan Stancek <jstancek@redhat.com>
To: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Cc: ltp-list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH v5 3/3] mlock/mlock02.c: add EPERM and ENOMEM errno tests
Date: Mon, 3 Mar 2014 15:28:49 -0500 (EST) [thread overview]
Message-ID: <40197796.12723624.1393878529754.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <1393845909.1984.13.camel@G08JYZSD130126>
----- Original Message -----
> From: "Zeng Linggang" <zenglg.jy@cn.fujitsu.com>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: "ltp-list" <ltp-list@lists.sourceforge.net>
> Sent: Monday, 3 March, 2014 12:25:09 PM
> Subject: [PATCH v5 3/3] mlock/mlock02.c: add EPERM and ENOMEM errno tests
>
> Add EPERM and ENOMEM errno tests for mlock(2).
>
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Looks good to me.
Reviewed-by: Jan Stancek <jstancek@redhat.com>
> ---
> testcases/kernel/syscalls/mlock/mlock02.c | 82
> ++++++++++++++++++++++++++++++-
> 1 file changed, 80 insertions(+), 2 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/mlock/mlock02.c
> b/testcases/kernel/syscalls/mlock/mlock02.c
> index 95c499d..bfed030 100644
> --- a/testcases/kernel/syscalls/mlock/mlock02.c
> +++ b/testcases/kernel/syscalls/mlock/mlock02.c
> @@ -23,11 +23,20 @@
> * 1. mlock() fails with -1 return value and sets errno to ENOMEM,
> * if some of the specified address range does not correspond to
> * mapped pages in the address space of the process.
> + * 2. mlock() fails with -1 return value and sets errno to ENOMEM,
> + * if (Linux 2.6.9 and later) the caller had a non-zero
> RLIMIT_MEMLOCK
> + * soft resource limit, but tried to lock more memory than the limit
> + * permitted. This limit is not enforced if the process is privileged
> + * (CAP_IPC_LOCK).
> + * 3. mlock() fails with -1 return value and sets errno to EPERM,
> + * if (Linux 2.6.9 and later) the caller was not privileged
> (CAP_IPC_LOCK)
> + * and its RLIMIT_MEMLOCK soft resource limit was 0.
> */
>
> #include <errno.h>
> #include <unistd.h>
> #include <sys/mman.h>
> +#include <pwd.h>
>
> #include "test.h"
> #include "usctest.h"
> @@ -40,14 +49,18 @@ char *TCID = "mlock02";
> static void setup(void);
> static void cleanup(void);
> static void test_enomem1(void);
> +static void test_enomem2(void);
> +static void test_eperm(void);
> static void mlock_verify(const void *, const size_t, const int);
>
> static size_t len;
> +static struct rlimit original;
> +static struct passwd *ltpuser;
>
> -static void (*test_func[])(void) = { test_enomem1 };
> +static void (*test_func[])(void) = { test_enomem1, test_enomem2, test_eperm
> };
>
> int TST_TOTAL = ARRAY_SIZE(test_func);
> -static int exp_enos[] = { ENOMEM, 0 };
> +static int exp_enos[] = { ENOMEM, EPERM, 0 };
>
> int main(int ac, char **av)
> {
> @@ -73,11 +86,17 @@ int main(int ac, char **av)
>
> static void setup(void)
> {
> + tst_require_root(NULL);
> +
> tst_sig(NOFORK, DEF_HANDLER, cleanup);
>
> TEST_PAUSE;
>
> + ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
> +
> len = getpagesize();
> +
> + SAFE_GETRLIMIT(cleanup, RLIMIT_MEMLOCK, &original);
> }
>
> static void test_enomem1(void)
> @@ -111,6 +130,65 @@ static void test_enomem1(void)
> mlock_verify(addr, len, ENOMEM);
> }
>
> +static void test_enomem2(void)
> +{
> + void *addr;
> + struct rlimit rl;
> +
> + if ((tst_kvercmp(2, 6, 9)) < 0) {
> + tst_resm(TCONF,
> + "ENOMEM error value test for this condition needs "
> + "kernel 2.6.9 or higher");
> + return;
> + }
> +
> + rl.rlim_max = len - 1;
> + rl.rlim_cur = len - 1;
> + SAFE_SETRLIMIT(cleanup, RLIMIT_MEMLOCK, &rl);
> +
> + addr = SAFE_MMAP(cleanup, NULL, len, PROT_READ,
> + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> +
> + SAFE_SETEUID(cleanup, ltpuser->pw_uid);
> +
> + mlock_verify(addr, len, ENOMEM);
> +
> + SAFE_SETEUID(cleanup, 0);
> +
> + SAFE_MUNMAP(cleanup, addr, len);
> +
> + SAFE_SETRLIMIT(cleanup, RLIMIT_MEMLOCK, &original);
> +}
> +
> +static void test_eperm(void)
> +{
> + void *addr;
> + struct rlimit rl;
> +
> + if ((tst_kvercmp(2, 6, 9)) < 0) {
> + tst_resm(TCONF,
> + "EPERM error value test needs kernel 2.6.9 or higher");
> + return;
> + }
> +
> + rl.rlim_max = 0;
> + rl.rlim_cur = 0;
> + SAFE_SETRLIMIT(cleanup, RLIMIT_MEMLOCK, &rl);
> +
> + addr = SAFE_MMAP(cleanup, NULL, len, PROT_READ,
> + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> +
> + SAFE_SETEUID(cleanup, ltpuser->pw_uid);
> +
> + mlock_verify(addr, len, EPERM);
> +
> + SAFE_SETEUID(cleanup, 0);
> +
> + SAFE_MUNMAP(cleanup, addr, len);
> +
> + SAFE_SETRLIMIT(cleanup, RLIMIT_MEMLOCK, &original);
> +}
> +
> static void mlock_verify(const void *addr, const size_t len, const int
> error)
> {
> TEST(mlock(addr, len));
> --
> 1.8.4.2
>
>
>
>
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works.
Faster operations. Version large binaries. Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2014-03-03 20:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-14 10:10 [LTP] [PATCH] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-14 10:12 ` [LTP] [PATCH 2/2] mlock/mlock02.c: add EPERM errno test Zeng Linggang
2014-02-14 10:54 ` Jan Stancek
2014-02-19 9:38 ` [LTP] [PATCH v2 1/2] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-19 9:40 ` [LTP] [PATCH v2 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-19 11:29 ` Jan Stancek
2014-02-20 9:40 ` [LTP] [PATCH v3 1/2] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-20 9:50 ` [LTP] [PATCH v3 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-20 11:05 ` Jan Stancek
2014-02-20 13:03 ` Jan Stancek
2014-02-21 9:03 ` Zeng Linggang
2014-03-03 7:47 ` [LTP] [PATCH v4 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Zeng Linggang
2014-03-03 7:50 ` [LTP] [PATCH v4 2/3] mlock/mlock02.c: cleanup Zeng Linggang
2014-03-03 7:51 ` [LTP] [PATCH v4 3/3] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-03-03 9:07 ` Jan Stancek
2014-03-03 11:22 ` [LTP] [PATCH v5 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Zeng Linggang
2014-03-03 11:23 ` [LTP] [PATCH v5 2/3] mlock/mlock02.c: cleanup Zeng Linggang
2014-03-03 11:25 ` [LTP] [PATCH v5 3/3] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-03-03 20:28 ` Jan Stancek [this message]
2014-03-04 5:02 ` Zeng Linggang
2014-03-04 5:33 ` [LTP] [PATCH v5 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Wanlong Gao
2014-03-04 6:17 ` Zeng Linggang
2014-02-21 1:04 ` [LTP] [PATCH v3 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-19 11:02 ` [LTP] [PATCH v2 1/2] mlock/mlock02.c: cleanup Jan Stancek
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=40197796.12723624.1393878529754.JavaMail.zimbra@redhat.com \
--to=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=zenglg.jy@cn.fujitsu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.