public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libmount/utils: use memmove when overlap possible
@ 2013-09-17 21:05 Dave Reisner
  2013-09-20  8:16 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Reisner @ 2013-09-17 21:05 UTC (permalink / raw)
  To: util-linux; +Cc: Dave Reisner

When unmounting some mountpoints as an unprivileged user (via the
'user' option in fstab), the umount fails. Debug output of 'umount
/opt' reveals:

17760: libmount: CXT: [0x22890e0]: do umount
17760: libmount: UTILS: moving to /opt parent
17760: libmount: CXT: current directory moved to / [last_component='opt']
17760: libmount: CXT: [0x22890e0]: umount(2) [target='pt', flags=0x00000000]

valgrind shows the problem:

==23544== Source and destination overlap in memcpy(0x58d1370, 0x58d1371, 4)
==23544==    at 0x4C2BBC3: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23544==    by 0x4E537C3: mnt_chdir_to_parent (utils.c:168)
==23544==    by 0x4E45E4C: mnt_context_do_umount (context_umount.c:601)
==23544==    by 0x4E46513: mnt_context_umount (context_umount.c:855)
==23544==    by 0x403476: umount_one (umount.c:299)
==23544==    by 0x402B34: main (umount.c:629)
==23544==

ref: https://bugs.archlinux.org/task/36968
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
 libmount/src/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 9f99241..3cab936 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -165,7 +165,7 @@ int mnt_chdir_to_parent(const char *target, char **filename)
 		if (!last || !*last)
 			memcpy(*filename, ".", 2);
 		else
-			memcpy(*filename, last, strlen(last) + 1);
+			memmove(*filename, last, strlen(last) + 1);
 	} else
 		free(buf);
 	return 0;
-- 
1.8.4


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

* Re: [PATCH] libmount/utils: use memmove when overlap possible
  2013-09-17 21:05 [PATCH] libmount/utils: use memmove when overlap possible Dave Reisner
@ 2013-09-20  8:16 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2013-09-20  8:16 UTC (permalink / raw)
  To: Dave Reisner; +Cc: util-linux

On Tue, Sep 17, 2013 at 05:05:09PM -0400, Dave Reisner wrote:
>  libmount/src/utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

 Oh, stupid bug. Applied, thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

end of thread, other threads:[~2013-09-20  8:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-17 21:05 [PATCH] libmount/utils: use memmove when overlap possible Dave Reisner
2013-09-20  8:16 ` Karel Zak

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