From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arnd Bergmann Subject: Re: [PATCH] Syscall arguments are unsigned long (full registers) Date: Mon, 04 Jul 2016 16:59:35 +0200 Message-ID: <3421998.D1ABSO4c36@wuerfel> References: <20160704142802.GL25121@tassilo.jf.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit Return-path: In-Reply-To: Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: "Tautschnig, Michael" Cc: Andi Kleen , "x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org" , "linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Jaswinder Singh List-Id: linux-api@vger.kernel.org On Monday, July 4, 2016 2:47:10 PM CEST Tautschnig, Michael wrote: > Thanks a lot for the immediate feedback. > > > On 4 Jul 2016, at 16:28, Andi Kleen wrote: > > > > On Mon, Jul 04, 2016 at 01:52:58PM +0000, Tautschnig, Michael wrote: > >> All syscall arguments are passed in as types of the same byte size as > >> unsigned long (width of full registers). Using a smaller type without a > >> cast may result in losing bits of information. In all other instances > >> apart from the ones fixed by the patch the code explicitly introduces > >> type casts (using, e.g., SYSCALL_DEFINE1). > >> > >> While goto-cc reported these problems at build time, it is noteworthy > >> that the calling conventions specified in the System V AMD64 ABI do > >> ensure that parameters 1-6 are passed via registers, thus there is no > >> implied risk of misaligned stack access. > > > > Does this actually fix anything? > > > > It will ensure the behaviour on 32 and 64-bit systems is consistent, i.e., > no truncation occurs. This is to ensure that future uses of these syscalls > do not face surprises. > > It looks to me like you are introducing a truncation, not removing one as your comment suggests: long do_arch_prctl(struct task_struct *task, int code, unsigned long addr); -long sys_arch_prctl(int code, unsigned long addr) +long sys_arch_prctl(unsigned long code, unsigned long addr) { return do_arch_prctl(current, code, addr); } This is the same truncation that we do with SYSCALL_DEFINE2(), clearing the top 32 bits of the 'code' parameter to ensure that user space doesn't pass data unexpectedly. That change seems reasonable, but why not just use SYSCALL_DEFINE2() directly for consistency with the other syscalls? Arnd From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754119AbcGDO64 (ORCPT ); Mon, 4 Jul 2016 10:58:56 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:55031 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751424AbcGDO6y (ORCPT ); Mon, 4 Jul 2016 10:58:54 -0400 From: Arnd Bergmann To: "Tautschnig, Michael" Cc: Andi Kleen , "x86@kernel.org" , "linux-api@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Jaswinder Singh Subject: Re: [PATCH] Syscall arguments are unsigned long (full registers) Date: Mon, 04 Jul 2016 16:59:35 +0200 Message-ID: <3421998.D1ABSO4c36@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-22-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <20160704142802.GL25121@tassilo.jf.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:UpccLrMNHNen8n117gPsUuslA39DqKtwntFU5cxPuUyJlP/Dddz 8mPKeWXCKt7SqnCnmVPHqusqvvqwRLbbzOdsVTNuSQ0Sv+VdEvSFrrdsi1X0BtGig1qmDxb q0X+Hj9Vlf3Zl0hkbFUTGL/0Sr8jJFAo3hW9im/ukyHdXcBW6pRoS0CeR98jYmynNHHBwR+ g3fxKUJemYEPGr/a9iABg== X-UI-Out-Filterresults: notjunk:1;V01:K0:A6uvlEKCeNI=:9DNU87sku9MTdV8zd+gIqS CsMweRIGU9oZnQivMm+bfHE3uCTxxcxoL2A3cHBIdKo/Qss4V6Qg39l8oTbxhRRw6SOsGHJ8N /xUq/1EqtrP8hKndP7tW0UcSKx9Hop3lX8bJQgSH6G5s4CfpbGdeOkGOlqjzJq833eDu/KCYr pREIxr29JwBcWdfdoEZP4J8kGTxDlIC1aU+dmpXsXDyxFxtiq/Sns6rmrjDxKcD3II3dm3zuj ZlutaqR2lcvDtOdKgdBvGpl0VB3JsQXJbTjQi3OAAAp8GCIJgXWFzdo6A25cEWhOtn+V2T9SS /IO6kEsPbXhEe2HB9sPHOoM6vyeoB8aKqA8mB9YiHWRC3dyTMRv73VHRZkWTJBbOywinNhJeE qfkXJYgGKF5qVDOwrgjJsLxjQLFbqgqjI7im1yAppU5jxOMJf92R3Ume8bRTXqfX8/DykcKab biWI9xKFhyc8v+5ZRiUg4k2Slq7OKAczQSqJpMlPWCiNumEUK/e5Z3/VYViDu/+RxHtjfuJeA 1DXm3m483xV6liQQO+ig6pDmhbyGGWWhE2HJMdSrPrD7OhvYhLchQ10b+mbJRSdFM0EY909/B /uplG6zQwQVkmR83nL9R979UeZWLu4l09G5jM6mA715ZSrnkJfttURL4c2l4uTtFtnZAOOIAo u7pTgj9T4PQlQW6OYfpkKQP0L+Av07DZVan2ol3U7lFNY3XyrHO/44/4YuShj6LHQ2Ecju++o QGOqvFN+hR9gZmql Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday, July 4, 2016 2:47:10 PM CEST Tautschnig, Michael wrote: > Thanks a lot for the immediate feedback. > > > On 4 Jul 2016, at 16:28, Andi Kleen wrote: > > > > On Mon, Jul 04, 2016 at 01:52:58PM +0000, Tautschnig, Michael wrote: > >> All syscall arguments are passed in as types of the same byte size as > >> unsigned long (width of full registers). Using a smaller type without a > >> cast may result in losing bits of information. In all other instances > >> apart from the ones fixed by the patch the code explicitly introduces > >> type casts (using, e.g., SYSCALL_DEFINE1). > >> > >> While goto-cc reported these problems at build time, it is noteworthy > >> that the calling conventions specified in the System V AMD64 ABI do > >> ensure that parameters 1-6 are passed via registers, thus there is no > >> implied risk of misaligned stack access. > > > > Does this actually fix anything? > > > > It will ensure the behaviour on 32 and 64-bit systems is consistent, i.e., > no truncation occurs. This is to ensure that future uses of these syscalls > do not face surprises. > > It looks to me like you are introducing a truncation, not removing one as your comment suggests: long do_arch_prctl(struct task_struct *task, int code, unsigned long addr); -long sys_arch_prctl(int code, unsigned long addr) +long sys_arch_prctl(unsigned long code, unsigned long addr) { return do_arch_prctl(current, code, addr); } This is the same truncation that we do with SYSCALL_DEFINE2(), clearing the top 32 bits of the 'code' parameter to ensure that user space doesn't pass data unexpectedly. That change seems reasonable, but why not just use SYSCALL_DEFINE2() directly for consistency with the other syscalls? Arnd