public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] read02: Fix the failure of mips architecture test
@ 2021-05-27  5:36 zhanglianjie
  2021-05-27  9:23 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: zhanglianjie @ 2021-05-27  5:36 UTC (permalink / raw)
  To: ltp

under mips architecture, writing to the buf of mmap PROT_NONE will
report an error EPERM.

Signed-off-by: zhanglianjie <zhanglianjie@uniontech.com>

diff --git a/testcases/kernel/syscalls/read/read02.c b/testcases/kernel/syscalls/read/read02.c
index 9199a95f6..650449e92 100644
--- a/testcases/kernel/syscalls/read/read02.c
+++ b/testcases/kernel/syscalls/read/read02.c
@@ -52,7 +52,9 @@ static struct tcase {
 } tcases[] = {
 	{&badfd, &bufaddr, 1, EBADF},
 	{&fd2, &bufaddr, 1, EISDIR},
-#ifndef UCLINUX
+#if defined(__mips)
+	{&fd3, &outside_buf, 1, EPERM},
+#elif !defined(UCLINUX)
 	{&fd3, &outside_buf, 1, EFAULT},
 #endif
 	{&fd4, &addr4, 1, EINVAL},
@@ -98,7 +100,7 @@ static void setup(void)

 	fd3 = SAFE_OPEN("test_file", O_RDWR);

-#if !defined(UCLINUX)
+#if !defined(UCLINUX) || defined(__mips)
 	outside_buf = SAFE_MMAP(0, 1, PROT_NONE,
 				MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 #endif
--
2.20.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [LTP] [PATCH v2] read02: Fix the failure of mips architecture test
  2021-05-27  5:36 [LTP] [PATCH v2] read02: Fix the failure of mips architecture test zhanglianjie
@ 2021-05-27  9:23 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2021-05-27  9:23 UTC (permalink / raw)
  To: ltp

Hi!
> under mips architecture, writing to the buf of mmap PROT_NONE will
> report an error EPERM.

That is reallly strange as far as I can tell the first check that vfs_read()
does is:

ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
        ssize_t ret;

        if (!(file->f_mode & FMODE_READ))
                return -EBADF;
        if (!(file->f_mode & FMODE_CAN_READ))
                return -EINVAL;
        if (unlikely(!access_ok(buf, count)))
                return -EFAULT;

...

Here for PROT_NONE the access_ok() will fail and we end up with EFAULT.

And the read syscall entry point calls ksys_read() which calls vfs_read() in a
case that the file descriptor is correct. So the only way how this can fail is
that you are not allowed to read from the file descriptor that the tests opens
for reading in the test setup() which should not happen. This looks more like a
kernel bug than anything else.

> Signed-off-by: zhanglianjie <zhanglianjie@uniontech.com>
> 
> diff --git a/testcases/kernel/syscalls/read/read02.c b/testcases/kernel/syscalls/read/read02.c
> index 9199a95f6..650449e92 100644
> --- a/testcases/kernel/syscalls/read/read02.c
> +++ b/testcases/kernel/syscalls/read/read02.c
> @@ -52,7 +52,9 @@ static struct tcase {
>  } tcases[] = {
>  	{&badfd, &bufaddr, 1, EBADF},
>  	{&fd2, &bufaddr, 1, EISDIR},
> -#ifndef UCLINUX
> +#if defined(__mips)
> +	{&fd3, &outside_buf, 1, EPERM},
> +#elif !defined(UCLINUX)
>  	{&fd3, &outside_buf, 1, EFAULT},
>  #endif
>  	{&fd4, &addr4, 1, EINVAL},
> @@ -98,7 +100,7 @@ static void setup(void)
> 
>  	fd3 = SAFE_OPEN("test_file", O_RDWR);
> 
> -#if !defined(UCLINUX)
> +#if !defined(UCLINUX) || defined(__mips)
>  	outside_buf = SAFE_MMAP(0, 1, PROT_NONE,
>  				MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
>  #endif

We do not support UCLINUX anymore so if anything the UCLINUX ifdefs should be removed first.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-27  9:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-27  5:36 [LTP] [PATCH v2] read02: Fix the failure of mips architecture test zhanglianjie
2021-05-27  9:23 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox