Skip to contentSkip to conversation

lib: don't pass NULL to strcmp in safe_mount

PATCH New Jan Stancek 3 participants 6 messages Nov 19, 2019 – Nov 21, 2019 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: don't pass NULL to strcmp in safe_mount

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")
---
 lib/safe_macros.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/safe_macros.c +2 -2
index c725c7d7763f..41fa4ca83004 100644
@@ -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),
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 lib: don't pass NULL to strcmp in safe_mount

Quoted 9 lines · Jan Stancek

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.

testcases/kernel/syscalls/pivot_root/pivot_root01.c +0 -0
@@ -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);
Quoted 40 lines
Fixes ae52b6f41bf3 ("lib: Fix safe_mount() when mounting NTFS on kernels

with NTFS support")

---
 lib/safe_macros.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/safe_macros.c +0 -0
index c725c7d7763f..41fa4ca83004 100644
@@ -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. */

lib/safe_macros.c +1 -1
-       if (strcmp(filesystemtype, "ntfs")) {
+       if (!filesystemtype || strcmp(filesystemtype, "ntfs")) {
                rval = mount(source, target, filesystemtype, mountflags,
data);
                if (!rval)
                        return 0;
lib/safe_macros.c +1 -1
@@ -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

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191120/2741c6a6/attachment-0001.htm>
#2 lore raw

PATCH 1/1 lib: don't pass NULL to strcmp in safe_mount

----- Original Message -----

Quoted 8 lines · Jan Stancek
Quoted 7 lines

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")) {

Quoted 8 lines
Quoted 3 lines

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.

#3 lore raw

PATCH 1/1 lib: don't pass NULL to strcmp in safe_mount

Quoted 16 lines · Jan Stancek

----- Original Message -----

Quoted 4 lines · Jan Stancek
Quoted 3 lines

Rachel reports, that pivot_root01 crashes on latest LTP:
Thread 3.1 "pivot_root01" received signal SIGSEGV, Segmentation

fault.

Quoted 8 lines
Quoted 7 lines

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'.

Quoted 8 lines
Quoted 3 lines

Good catch.

And shouldn't we give a "correct" fs_type in pivot_root01.c too?

Otherwise,

Quoted 1 line

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.

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

PATCH 1/1 lib: don't pass NULL to strcmp in safe_mount

----- Original Message -----

Quoted 2 lines

Hi!
Thanks for fixing this, acked.

Pushed.