All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount
@ 2019-11-19 10:29 Jan Stancek
  2019-11-20  6:02 ` Li Wang
  2019-11-20 11:22 ` Cyril Hrubis
  0 siblings, 2 replies; 6+ messages in thread
From: Jan Stancek @ 2019-11-19 10:29 UTC (permalink / raw)
  To: ltp

Rachel reports, that pivot_root01 crashes on latest LTP:
  Thread 3.1 "pivot_root01" received signal SIGSEGV, Segmentation fault.
  0x00000000004062c4 in safe_mount (file=file@entry=0x413017 "pivot_root01.c"
  733             if (strcmp(filesystemtype, "ntfs")) {

Don't pass NULL ptr to strcmp. Also fix return in unreachable path,
to suppress warning about returning uninitialized 'rval'.

Fixes: ae52b6f41bf3 ("lib: Fix safe_mount() when mounting NTFS on kernels with NTFS support")
Reported-by: Rachel Sibley <rasibley@redhat.com>
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 lib/safe_macros.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index c725c7d7763f..41fa4ca83004 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -730,7 +730,7 @@ int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
 	 * Don't try using the kernel's NTFS driver when mounting NTFS, since
 	 * the kernel's NTFS driver doesn't have proper write support.
 	 */
-	if (strcmp(filesystemtype, "ntfs")) {
+	if (!filesystemtype || strcmp(filesystemtype, "ntfs")) {
 		rval = mount(source, target, filesystemtype, mountflags, data);
 		if (!rval)
 			return 0;
@@ -764,7 +764,7 @@ int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
 			 mountflags, data);
 	}
 
-	return rval;
+	return -1;
 }
 
 int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void),
-- 
1.8.3.1


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

* [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount
  2019-11-19 10:29 [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount Jan Stancek
@ 2019-11-20  6:02 ` Li Wang
  2019-11-20  6:51   ` Jan Stancek
  2019-11-20 11:22 ` Cyril Hrubis
  1 sibling, 1 reply; 6+ messages in thread
From: Li Wang @ 2019-11-20  6:02 UTC (permalink / raw)
  To: ltp

On Tue, Nov 19, 2019 at 6:29 PM Jan Stancek <jstancek@redhat.com> wrote:

> Rachel reports, that pivot_root01 crashes on latest LTP:
>   Thread 3.1 "pivot_root01" received signal SIGSEGV, Segmentation fault.
>   0x00000000004062c4 in safe_mount (file=file@entry=0x413017
> "pivot_root01.c"
>   733             if (strcmp(filesystemtype, "ntfs")) {
>
> Don't pass NULL ptr to strcmp. Also fix return in unreachable path,
> to suppress warning about returning uninitialized 'rval'.
>

Good catch.

And shouldn't we give a "correct" fs_type in pivot_root01.c too? Otherwise,
the test would be failed on an invalid mounted operation I guess.

--- a/testcases/kernel/syscalls/pivot_root/pivot_root01.c
+++ b/testcases/kernel/syscalls/pivot_root/pivot_root01.c
@@ -107,7 +107,7 @@ static void run(unsigned int test_case)
         * Create an initial root dir. pivot_root doesn't work if the
initial root
         * dir is a initramfs, so use chroot to create a safe environment
         */
-       SAFE_MOUNT("none", "/", NULL, MS_REC|MS_PRIVATE, NULL);
+       SAFE_MOUNT("none", "/", "none", MS_REC|MS_PRIVATE, NULL);
        SAFE_MOUNT("none", CHROOT_DIR, "tmpfs", 0, 0);
        SAFE_CHROOT(CHROOT_DIR);



>
> Fixes: ae52b6f41bf3 ("lib: Fix safe_mount() when mounting NTFS on kernels
> with NTFS support")
> Reported-by: Rachel Sibley <rasibley@redhat.com>
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
>  lib/safe_macros.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/safe_macros.c b/lib/safe_macros.c
> index c725c7d7763f..41fa4ca83004 100644
> --- a/lib/safe_macros.c
> +++ b/lib/safe_macros.c
> @@ -730,7 +730,7 @@ int safe_mount(const char *file, const int lineno,
> void (*cleanup_fn)(void),
>          * Don't try using the kernel's NTFS driver when mounting NTFS,
> since
>          * the kernel's NTFS driver doesn't have proper write support.
>          */
> -       if (strcmp(filesystemtype, "ntfs")) {
> +       if (!filesystemtype || strcmp(filesystemtype, "ntfs")) {
>                 rval = mount(source, target, filesystemtype, mountflags,
> data);
>                 if (!rval)
>                         return 0;
> @@ -764,7 +764,7 @@ int safe_mount(const char *file, const int lineno,
> void (*cleanup_fn)(void),
>                          mountflags, data);
>         }
>
> -       return rval;
> +       return -1;
>  }
>
>  int safe_umount(const char *file, const int lineno, void
> (*cleanup_fn)(void),
> --
> 1.8.3.1
>
>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191120/2741c6a6/attachment-0001.htm>

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

* [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount
  2019-11-20  6:02 ` Li Wang
@ 2019-11-20  6:51   ` Jan Stancek
  2019-11-20  7:53     ` Li Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Stancek @ 2019-11-20  6:51 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> On Tue, Nov 19, 2019 at 6:29 PM Jan Stancek <jstancek@redhat.com> wrote:
> 
> > Rachel reports, that pivot_root01 crashes on latest LTP:
> >   Thread 3.1 "pivot_root01" received signal SIGSEGV, Segmentation fault.
> >   0x00000000004062c4 in safe_mount (file=file@entry=0x413017
> > "pivot_root01.c"
> >   733             if (strcmp(filesystemtype, "ntfs")) {
> >
> > Don't pass NULL ptr to strcmp. Also fix return in unreachable path,
> > to suppress warning about returning uninitialized 'rval'.
> >
> 
> Good catch.
> 
> And shouldn't we give a "correct" fs_type in pivot_root01.c too? Otherwise,
> the test would be failed on an invalid mounted operation I guess.

Per man-page, it should be ignored.


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

* [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount
  2019-11-20  6:51   ` Jan Stancek
@ 2019-11-20  7:53     ` Li Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Li Wang @ 2019-11-20  7:53 UTC (permalink / raw)
  To: ltp

On Wed, Nov 20, 2019 at 2:51 PM Jan Stancek <jstancek@redhat.com> wrote:

>
>
> ----- Original Message -----
> > On Tue, Nov 19, 2019 at 6:29 PM Jan Stancek <jstancek@redhat.com> wrote:
> >
> > > Rachel reports, that pivot_root01 crashes on latest LTP:
> > >   Thread 3.1 "pivot_root01" received signal SIGSEGV, Segmentation
> fault.
> > >   0x00000000004062c4 in safe_mount (file=file@entry=0x413017
> > > "pivot_root01.c"
> > >   733             if (strcmp(filesystemtype, "ntfs")) {
> > >
> > > Don't pass NULL ptr to strcmp. Also fix return in unreachable path,
> > > to suppress warning about returning uninitialized 'rval'.
> > >
> >
> > Good catch.
> >
> > And shouldn't we give a "correct" fs_type in pivot_root01.c too?
> Otherwise,
> > the test would be failed on an invalid mounted operation I guess.
>
> Per man-page, it should be ignored.
>

Ok, then this patch looks good.

Reviewed-by: Li Wang <liwang@redhat.com>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191120/e579d101/attachment.htm>

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

* [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount
  2019-11-19 10:29 [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount Jan Stancek
  2019-11-20  6:02 ` Li Wang
@ 2019-11-20 11:22 ` Cyril Hrubis
  2019-11-21  8:10   ` Jan Stancek
  1 sibling, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2019-11-20 11:22 UTC (permalink / raw)
  To: ltp

Hi!
Thanks for fixing this, acked.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount
  2019-11-20 11:22 ` Cyril Hrubis
@ 2019-11-21  8:10   ` Jan Stancek
  0 siblings, 0 replies; 6+ messages in thread
From: Jan Stancek @ 2019-11-21  8:10 UTC (permalink / raw)
  To: ltp

----- Original Message -----
> Hi!
> Thanks for fixing this, acked.

Pushed.


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

end of thread, other threads:[~2019-11-21  8:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-19 10:29 [LTP] [PATCH] lib: don't pass NULL to strcmp in safe_mount Jan Stancek
2019-11-20  6:02 ` Li Wang
2019-11-20  6:51   ` Jan Stancek
2019-11-20  7:53     ` Li Wang
2019-11-20 11:22 ` Cyril Hrubis
2019-11-21  8:10   ` Jan Stancek

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.