[PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request

Dmitry V. Levin ldv at altlinux.org
Tue Dec 11 20:27:09 UTC 2018


On Tue, Dec 11, 2018 at 07:23:05PM +0300, Dmitry V. Levin wrote:
> On Tue, Dec 11, 2018 at 04:29:54PM +0100, Oleg Nesterov wrote:
> > On 12/10, Dmitry V. Levin wrote:
> > > On Mon, Dec 10, 2018 at 03:11:07PM +0100, Oleg Nesterov wrote:
> > > > On 12/10, Dmitry V. Levin wrote:
> > > > >
> > > > > +struct ptrace_syscall_info {
> > > > > +	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
> > > > > +	__u8 __pad0[3];
> > > > > +	__u32 arch;
> > > > > +	__u64 instruction_pointer;
> > > > > +	__u64 stack_pointer;
> > > > > +	__u64 frame_pointer;
> > > > > +	union {
> > > > > +		struct {
> > > > > +			__u64 nr;
> > > > > +			__u64 args[6];
> > > > > +		} entry;
> > > > > +		struct {
> > > > > +			__s64 rval;
> > > > > +			__u8 is_error;
> > > > > +			__u8 __pad1[7];
> > > > > +		} exit;
> > > > > +		struct {
> > > > > +			__u64 nr;
> > > > > +			__u64 args[6];
> > > > > +			__u32 ret_data;
> > > > > +			__u8 __pad2[4];
> > > > > +		} seccomp;
> > > > > +	};
> > > > > +};
> > > >
> > > > Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply can't
> > > > understand why...
> > >
> > > I suppose the idea behind the use of these pads was to make the structure
> > > arch-independent.
> > 
> > Still can't understand... are you saying that without (say) __pad2[4]
> > sizeof(ptrace_syscall_info) or offsetofend(ptrace_syscall_info, seccomp)
> > will depend on arch? Or what? I am just curious.
> 
> Yes, without padding these sizes will depend on architecture:
> 
> $ cat t.c
> #include <linux/types.h>
> int main() {
> 	struct s {
> 		__u64 nr;
> 		__u64 args[6];
> 		__u32 ret_data;
> 	};
> 	return sizeof(struct s);
> }
> 
> $ gcc -m64 -Wall -O2 t.c && ./a.out; echo $?
> 64
> $ gcc -m32 -Wall -O2 t.c && ./a.out; echo $?
> 60
> 
> This happens because __u64 has 32-bit alignment on some 32-bit
> architectures like x86.
> 
> There is also m68k where __u32 has 16-bit alignment.

Said that, I think it would be better if PTRACE_GET_SYSCALL_INFO
did not take these trailing pads into account, e.g.

-       return offsetofend(struct ptrace_syscall_info, seccomp);
+       return offsetofend(struct ptrace_syscall_info, seccomp.ret_data);
...
-       return offsetofend(struct ptrace_syscall_info, exit);
+       return offsetofend(struct ptrace_syscall_info, exit.is_error);

The reason is that it would allow to fill these trailing pads with
something useful in the future.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20181211/83b3e1b9/attachment.bin>


More information about the Strace-devel mailing list