aarch64 strace decoding of 32-bit arm statfs64...

Dmitry V. Levin ldv at altlinux.org
Wed Mar 18 16:42:55 UTC 2015


On Tue, Mar 17, 2015 at 10:29:23PM -0700, enh wrote:
> hmm. i wonder if this changed at some point? the arm64 kernel has this:
> 
> compat_sys_statfs64_wrapper:
>         mov     w3, #84
>         cmp     w1, #88
>         csel    w1, w3, w1, eq
>         b       compat_sys_statfs64
> ENDPROC(compat_sys_statfs64_wrapper)
> 
> compat_sys_fstatfs64_wrapper:
>         mov     w3, #84
>         cmp     w1, #88
>         csel    w1, w3, w1, eq
>         b       compat_sys_fstatfs64
> ENDPROC(compat_sys_fstatfs64_wrapper)
> 
> and the arm kernel has the equivalent:
> 
> sys_statfs64_wrapper:
>                 teq     r1, #88
>                 moveq   r1, #84
>                 b       sys_statfs64
> ENDPROC(sys_statfs64_wrapper)
> 
> sys_fstatfs64_wrapper:
>                 teq     r1, #88
>                 moveq   r1, #84
>                 b       sys_fstatfs64
> ENDPROC(sys_fstatfs64_wrapper)
> 
> oh, there's a comment in arch/arm/kernel/sys_oabi-compat.c:
> 
>  * sys_statfs64:
>  * sys_fstatfs64:
>  *
>  *   struct statfs64 has extra padding with EABI growing its size from
>  *   84 to 88.  This struct is now __attribute__((packed,aligned(4)))
>  *   with a small assembly wrapper to force the sz argument to 84 if it is 88
>  *   to avoid copying the extra padding over user space unexpecting it.
> 
> bionic doesn't have the packed attribute and our sizeof is 88.
> 
> adding this in both sys_statfs64 and sys_fstatfs64 fixed things for me
> but maybe you have a better idea?
> 
> +#if defined ARM || defined AARCH64 /* eabi structs have padding */
> + else if (tcp->u_arg[1] == sizeof(struct compat_statfs64) + 4)
> + printcompat_statfs64(tcp, tcp->u_arg[2]);
> +#endif

As both sizes appear to be valid, we have no choice but to support this
diversity.  I'm going to install this patch:

--- a/statfs.c
+++ b/statfs.c
@@ -128,6 +128,10 @@ struct compat_statfs64 {
   __attribute__ ((packed, aligned(4)))
 #endif
 ;
+#if defined AARCH64 || defined ARM
+/* See arch/arm/kernel/sys_oabi-compat.c for details. */
+# define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct compat_statfs64) + 4)
+#endif
 
 static void
 printcompat_statfs64(struct tcb *tcp, const long addr)
@@ -157,16 +161,19 @@ printcompat_statfs64(struct tcb *tcp, const long addr)
 	tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
 }
 
-int
-sys_statfs64(struct tcb *tcp)
+static int
+do_statfs64_fstatfs64(struct tcb *tcp)
 {
 	if (entering(tcp)) {
-		printpath(tcp, tcp->u_arg[0]);
 		tprintf(", %lu, ", tcp->u_arg[1]);
 	} else {
 		if (tcp->u_arg[1] == sizeof(struct statfs64))
 			printstatfs64(tcp, tcp->u_arg[2]);
-		else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
+		else if (tcp->u_arg[1] == sizeof(struct compat_statfs64)
+#ifdef COMPAT_STATFS64_PADDED_SIZE
+			 || tcp->u_arg[1] == COMPAT_STATFS64_PADDED_SIZE
+#endif
+									)
 			printcompat_statfs64(tcp, tcp->u_arg[2]);
 		else
 			tprints("{???}");
@@ -175,20 +182,19 @@ sys_statfs64(struct tcb *tcp)
 }
 
 int
+sys_statfs64(struct tcb *tcp)
+{
+	if (entering(tcp))
+		printpath(tcp, tcp->u_arg[0]);
+	return do_statfs64_fstatfs64(tcp);
+}
+
+int
 sys_fstatfs64(struct tcb *tcp)
 {
-	if (entering(tcp)) {
+	if (entering(tcp))
 		printfd(tcp, tcp->u_arg[0]);
-		tprintf(", %lu, ", tcp->u_arg[1]);
-	} else {
-		if (tcp->u_arg[1] == sizeof(struct statfs64))
-			printstatfs64(tcp, tcp->u_arg[2]);
-		else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
-			printcompat_statfs64(tcp, tcp->u_arg[2]);
-		else
-			tprints("{???}");
-	}
-	return 0;
+	return do_statfs64_fstatfs64(tcp);
 }
 #endif /* HAVE_STRUCT_STATFS64 */
 
-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20150318/90b6cee5/attachment.bin>


More information about the Strace-devel mailing list