From: Xiao Yang <yangx.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/3] syscalls/shmat03.c: add new regression test
Date: Thu, 1 Jun 2017 19:53:58 +0800 [thread overview]
Message-ID: <59300056.1020107@cn.fujitsu.com> (raw)
In-Reply-To: <20170529145709.GC6618@rei.lan>
On 2017/05/29 22:57, Cyril Hrubis wrote:
> Hi!
>> + addr = shmat(shm_id, LOCATION, SHM_RND);
>> + if (addr != (void *)-1)
>> + tst_res(TINFO, "shmat() attached a nil-page unexpectedly");
>> + else
>> + tst_res(TINFO, "shmat() didn't attach a nil-page");
>> +
>> + ((char *)addr)[0] = 'A';
>
> So if shmat() fails we try to write to (char*)-1 address, that does not
> sound right. Why don't we exit the test with TPASS in that case and skip
> the part that tries to write to invalid address?
>
> Or at least dereference NULL here instead of the address returned from
> shmat() since that is guaranteed to SEGFAULT.
Hi Cyril
I failed to call shmat() as root and returned EACCES if selinux is
Enforcing.
Do you know how to fix this problem?
Thanks,
Xiao Yang.
>> + tst_res(TINFO, "shmat() wrote data to shmaddr:%p unexpectedly", addr);
>> +
>> + SAFE_SHMDT(addr);
>> +
>> + exit(0);
>> +}
>> +
>> +static void do_shmat(unsigned int n)
>> +{
>> + pid_t pid;
>> + int status;
>> + struct tcase *tc =&tcases[n];
>> +
>> + pid = SAFE_FORK();
>> + if (!pid)
>> + verify_shmat(tc->exp_usr);
>> +
>> + SAFE_WAITPID(pid,&status, 0);
>> +
>> + if (WIFEXITED(status)) {
>> + tst_res(TFAIL, "%s mapped nil-page in shmat() unexpectedly",
>> + tc->des);
>> + return;
>> + }
>> +
>> + if (WIFSIGNALED(status)&& WTERMSIG(status) == SIGSEGV) {
>> + tst_res(TPASS, "%s didn't map nil-page in shmat(), and was "
>> + "killed by %s as expected", tc->des,
>> + tst_strsig(WTERMSIG(status)));
>> + } else {
>> + tst_res(TFAIL, "%s didn't map nil-page in shmat(), and was "
>> + "killed by %s unexpectedly", tc->des,
>> + tst_strsig(WTERMSIG(status)));
>> + }
>> +}
>> +
>> +static void setup(void)
>> +{
>> + key_t shm_key;
>> +
>> + shm_key = GETIPCKEY();
>> + shm_id = SAFE_SHMGET(shm_key, 4096, 0777 | IPC_CREAT);
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> + if (shm_id != -1)
>> + SAFE_SHMCTL(shm_id, IPC_RMID, NULL);
>> +}
>> +
>> +static struct tst_test test = {
>> + .tid = "shmat03",
>> + .needs_root = 1,
>> + .forks_child = 1,
>> + .test = do_shmat,
>> + .tcnt = ARRAY_SIZE(tcases),
>> + .setup = setup,
>> + .cleanup = cleanup
>> +};
>> --
>> 1.8.3.1
>>
>>
>>
>>
>> --
>> Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2017-06-01 11:53 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-14 10:15 [LTP] [PATCH 1/3] tst_safe_sysv_ipc: add shared memory related macros Xiao Yang
2017-04-14 10:15 ` [LTP] [PATCH 2/3] syscalls/shmat0*: cleanup && convert to new API Xiao Yang
2017-05-29 14:11 ` Cyril Hrubis
2017-06-01 9:03 ` Xiao Yang
2017-04-14 10:15 ` [LTP] [PATCH 3/3] syscalls/shmat03.c: add new regression test Xiao Yang
2017-05-29 14:57 ` Cyril Hrubis
2017-06-01 11:49 ` [LTP] [PATCH v2 1/3] tst_safe_sysv_ipc: add shared memory related macros Xiao Yang
2017-06-01 11:49 ` [LTP] [PATCH v2 2/3] syscalls/shmat0*: cleanup && convert to new API Xiao Yang
2017-06-29 16:14 ` Cyril Hrubis
2017-06-30 2:30 ` [LTP] [PATCH v3] " Xiao Yang
2017-06-30 14:54 ` Cyril Hrubis
2017-07-03 3:09 ` [LTP] [PATCH v4] " Xiao Yang
2017-07-07 12:29 ` Cyril Hrubis
2017-06-01 11:49 ` [LTP] [PATCH v2 3/3] syscalls/shmat03.c: add new regression test Xiao Yang
2017-06-22 9:41 ` [LTP] [PATCH v2 1/3] tst_safe_sysv_ipc: add shared memory related macros Xiao Yang
2017-06-22 15:29 ` Cyril Hrubis
2017-06-01 11:53 ` Xiao Yang [this message]
2017-06-22 10:09 ` [LTP] [PATCH 3/3] syscalls/shmat03.c: add new regression test Xiao Yang
2017-06-22 11:08 ` Xiao Yang
2017-06-22 12:02 ` Jan Stancek
2017-06-22 15:11 ` [LTP] [PATCH v2 2/2] clone09: add a test for CLONE_NEWNET flag Cyril Hrubis
2017-06-23 7:22 ` Richard Palethorpe
2017-06-23 1:07 ` [LTP] [PATCH 3/3] syscalls/shmat03.c: add new regression test Xiao Yang
2017-06-20 13:40 ` Richard Palethorpe
2017-05-19 1:19 ` [LTP] [PATCH 1/3] tst_safe_sysv_ipc: add shared memory related macros Xiao Yang
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=59300056.1020107@cn.fujitsu.com \
--to=yangx.jy@cn.fujitsu.com \
--cc=ltp@lists.linux.it \
/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