Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp904515imu; Tue, 11 Dec 2018 09:19:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/WZyqvBOddMG2Y2yfIajX0kKVnhuzoO8R+aZIHSOPMJ+Fb7jkMrHSRjAlJJtyyJOmDvIBI2 X-Received: by 2002:a65:624c:: with SMTP id q12mr15330437pgv.379.1544548784446; Tue, 11 Dec 2018 09:19:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548784; cv=none; d=google.com; s=arc-20160816; b=s0nzly8Zs5ADoozWMedwykhWCtWXIPPfA764L0W21F8RwBsXtOWxAkF5ff65AM9zYZ R4KHHrUZfqUKgqy7Ax3w2uqi67EUzVZTeCeX0vhMaKAXxYwF06YDJzptVtkuqpCINhzE Sq3Kg0Knske8c5MqZBkCa7kjpCx2KnF5RA7sgM5RvgTxLvdHFEzaYawCKVowrIAB83K7 nS/Sk0A96AE8GD9XTr8p4OARuEUv/Fe9cMkv7azz+vx5ElP39u32Pm6/gOLX/orRWqwL dAla+00IYdruGyrV5fRpCBcxR7ikjJey1JAfAxLM1lqHAIbq69QQpTlnLDj+y2tWmSEr zfyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=WHxWcxF8r6XSsa88cn0j7s26QuBi5fFJ9RQq0+KFMLo=; b=Y7IcHPFpdCC7hHvnNPAilcagW8THKyfw6xXR4Dl5af+P/4jpSeCHXH2K7+lSNbuvRD sW4bpTD/kaQPUEVf1WRWzrfhEZ02NGHnnWDk5VkaIOlgaWOEjNbRA0q450bkivoJuAvm SEtaI3HkrspNvcGAPWyDoS2u09d2QiPfbDE1RZttGAdfi/hiylOaPclUVOe9TEQh773U v5ftfq4UUt3GxJIZDns2H/Y3qI5maIkxMwyOPhD+Szlyd1xoMEfH+YmZ2DyhyWaNEa+R IUVBZR7KkyntYi2YUS6w++6UYKQjrTl5Lih7w72xFlUj4FbeTp6zj1iKI5WptsEMuEEz WC1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si12076503pgn.551.2018.12.11.09.19.29; Tue, 11 Dec 2018 09:19:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728349AbeLKQXM (ORCPT + 99 others); Tue, 11 Dec 2018 11:23:12 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:48318 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727686AbeLKQXJ (ORCPT ); Tue, 11 Dec 2018 11:23:09 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 94A9872CC6C; Tue, 11 Dec 2018 19:23:05 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 7C9EB7CFA6D; Tue, 11 Dec 2018 19:23:05 +0300 (MSK) Date: Tue, 11 Dec 2018 19:23:05 +0300 From: "Dmitry V. Levin" To: Oleg Nesterov Cc: Andy Lutomirski , Elvira Khabirova , Eugene Syromyatnikov , Kees Cook , Jann Horn , linux-api@vger.kernel.org, strace-devel@lists.strace.io, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request Message-ID: <20181211162305.GA480@altlinux.org> References: <20181210042352.GA6092@altlinux.org> <20181210043126.GX6131@altlinux.org> <20181210141107.GB4177@redhat.com> <20181210162131.GG14149@altlinux.org> <20181211152953.GA8504@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="a8Wt8u1KmwUX3Y2C" Content-Disposition: inline In-Reply-To: <20181211152953.GA8504@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --a8Wt8u1KmwUX3Y2C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 simp= ly can't > > > understand why... > > > > I suppose the idea behind the use of these pads was to make the structu= re > > arch-independent. >=20 > 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 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. > > I don't think we really need to keep it exactly the same on all > > architectures - the only practical requirement is to avoid any compat > > issues, but I don't mind keeping the structure arch-independent. >=20 > OK, but may be you can add a short comment to explain these pads. Alternatively, we could use __attribute__((aligned(N))), e.g. struct ptrace_syscall_info { __u8 op; /* PTRACE_SYSCALL_INFO_* */ __u32 arch __attribute__((aligned(4))); __u64 instruction_pointer; __u64 stack_pointer; union { struct { __u64 nr __attribute__((aligned(8))); __u64 args[6]; } entry; struct { __s64 rval __attribute__((aligned(8))); __u8 is_error; } exit; struct { __u64 nr __attribute__((aligned(8))); __u64 args[6]; __u32 ret_data; } seccomp; }; }; Do you prefer __attribute__((aligned(N))) to padding? --=20 ldv --a8Wt8u1KmwUX3Y2C Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJcD+RpAAoJEAVFT+BVnCUIcBAQAIk2DIaVO8win99bfrthySyg 4qzAMo2GFFPBGMrOaj8q+9FcfOS+atOy6twMOyuBahMHzUZ4FCfBWfMwmKKlmqlN fRaj8nnwyISEhR8pcV2qRgqrdYw+kB//81GoY9OALju+H6jP+xuJ58aV+O1D1aiM PiuwWBvScc6fgAo/fRac9UKMwDMfxfdw0CJ99VmnJz3AhbKp2e19Vo1nzw6Jqp41 Tx11Tvd97+qIT9E2NdRH+7kt8APthvZW0lo+8fqnGxJu49ulS2oRh8Vk5K6ZjXKe x9sRyfWz1rMSyS4P/KaDE8cX4wk4c6n158EeYK8al/McUeIz9hATmdGjOv8vsQFJ OniRAY3sTYnMX63pY7sIENM+1uILbBZQbyXsHm6haB6Cpog8wZjiTfL0GuvfNY3u eo5xHeAxMEVOQegHDOY7Q2WdrsdY2TzjM3FWzDm4ZTRr7MW16eQZXtHKryIe4pTC rfxwfvgtbVDtkfk9mpjnL/7+P6ATGzecSAlzT10zyinTnnX0qElau7k+RHCUTczZ wztUiTvLzPbMaDVf23anqO5YYt5OBEPOAn3e0xX2h85QpFC2nEaUIWEK9hHDgwKB mhz6ga7Iup10vckeP/b/qau4tWYMwMGCUqVobFSa+bcmIl6U3293uHHEpcZsKCzZ LVQwqcKiPj4ANJ4TkiMj =H7Ic -----END PGP SIGNATURE----- --a8Wt8u1KmwUX3Y2C--