Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1769428imu; Wed, 12 Dec 2018 04:07:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/XY/MG+W+MUhLxOnDC2XC2zzkAPhRNIDWxzwmNh1+om5p8n1B6Gfq+S14cNW5jZHLNkbLCm X-Received: by 2002:a63:d104:: with SMTP id k4mr17884563pgg.227.1544616459562; Wed, 12 Dec 2018 04:07:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544616459; cv=none; d=google.com; s=arc-20160816; b=IkDpgymBt0z9GkgOX3LwKAj4hjZW3jNNwtJKUmfaOFzbCmgnN5SIxXL2wtLe1g6Zz4 t0HW4iQmlRMAPlrp2Cls/UJ67+5PiH6GCjMzzFcI0SlA6Psu7euawqhMx52O/QyJn6ie TiwewBQOoKDMBv/8CHt6+mYNAqZG1t1fsbNXpzfm1pRF0LKeOmz0q8+QE9+7H9h0EGT1 bLa3YJb07o5KNteFbW5x3iO2Dy/YLZD5bHwr6dXQVplfFM9hfY/JHJW46ewIQcHuquix SCsDFriJCfZlMa8kY5KCfJcLvb87IhRwcJ7OS/l9aZ5FNbbHlojxoM9lTqCdB5WVg3j4 Al4g== 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=257oX4EuofmPO6V1NV40p/GGo2wG1whygyi5n/82QsU=; b=ageexEoP9wzutFZlEcwp4+nuHRj3nKoO0wPPMm8NjBGUTMqfqGFfqfsvR1a0uY8hrM A+Iup8v7we6IesFb1KyNAewSK0KgiJfbBAZCYO7347YVpHwTHsshC0EyJ35K03HUlIu5 rwUih3BZ0B6/An0dNdjbVbS4KynCq0Ro5R9/kvafMOMaaOeTzTynuuxg607khT+R48Jd KfAgBBVc2itoA8pk5oHBm8QIAU5O675HriTK4C7poIgKFpQTV6/UmHlJkkjFT7Dc7EFn HgDxjWSt8phXcCFDqYORYix4S3YwTVI/kdL2n1oOHfkPBY3EurRdFIk5KuYnJmL6K7Nd kpnQ== 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 z136si15292849pgz.28.2018.12.12.04.07.23; Wed, 12 Dec 2018 04:07:39 -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 S1727386AbeLLMEX (ORCPT + 99 others); Wed, 12 Dec 2018 07:04:23 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:40860 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726970AbeLLMEW (ORCPT ); Wed, 12 Dec 2018 07:04:22 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 4932772CA65; Wed, 12 Dec 2018 15:04:17 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 3EC0D7CFF3E; Wed, 12 Dec 2018 15:04:17 +0300 (MSK) Date: Wed, 12 Dec 2018 15:04:17 +0300 From: "Dmitry V. Levin" To: Geert Uytterhoeven Cc: Oleg Nesterov , Andy Lutomirski , lineprinter@altlinux.org, Eugene Syromiatnikov , linux-m68k , Linux Kernel Mailing List Subject: Re: [PATCH v5 13/25] m68k: add asm/syscall.h Message-ID: <20181212120417.GC15561@altlinux.org> References: <20181210042352.GA6092@altlinux.org> <20181210043010.GM6131@altlinux.org> <20181210124059.GA11942@altlinux.org> <20181210133025.GG11942@altlinux.org> <20181212085516.GA13288@altlinux.org> <20181212092712.GD13288@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="OwLcNYc0lM97+oe1" Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --OwLcNYc0lM97+oe1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Geert, On Wed, Dec 12, 2018 at 10:43:33AM +0100, Geert Uytterhoeven wrote: > On Wed, Dec 12, 2018 at 10:27 AM Dmitry V. Levin wrote: > > On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote: > > > On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin wr= ote: > > > > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote: > > > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrot= e: > > > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin wrote: > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven = wrote: > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin wrote: > > > > > > > > > syscall_get_* functions are required to be implemented on= all > > > > > > > > > architectures in order to extend the generic ptrace API w= ith > > > > > > > > > PTRACE_GET_SYSCALL_INFO request. > > > > > > > > > > > > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 = syscall_get_* > > > > > > > > > functions as documented in asm-generic/syscall.h: syscall= _get_nr, > > > > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_ret= urn_value, > > > > > > > > > and syscall_get_arch. > > > > > > > > > > > > > > > > > > Cc: Geert Uytterhoeven > > > > > > > > > Cc: Oleg Nesterov > > > > > > > > > Cc: Andy Lutomirski > > > > > > > > > Cc: Elvira Khabirova > > > > > > > > > Cc: Eugene Syromyatnikov > > > > > > > > > Cc: linux-m68k@lists.linux-m68k.org > > > > > > > > > Signed-off-by: Dmitry V. Levin > > > > > > > > > --- > > > > > > > > > > > > > > > > > > Notes: > > > > > > > > > v5: added syscall_get_nr, syscall_get_arguments, sysc= all_get_error, > > > > > > > > > and syscall_get_return_value > > > > > > > > > v1: added syscall_get_arch > > > > > > > > > > > > > > > > > --- /dev/null > > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h > > > > > > > > > @@ -0,0 +1,39 @@ > > > > > > > > > > > > > > > > > +static inline void > > > > > > > > > +syscall_get_arguments(struct task_struct *task, struct p= t_regs *regs, > > > > > > > > > + unsigned int i, unsigned int n, uns= igned long *args) > > > > > > > > > +{ > > > > > > > > > + BUG_ON(i + n > 6); > > > > > > > > > > > > > > > > Does this have to crash the kernel? > > > > > > > > > > > > > > This is what most of other architectures do, but we could cho= ose > > > > > > > a softer approach, e.g. use WARN_ON_ONCE instead. > > > > > > > > > > > > > > > Perhaps you can return an error code instead? > > > > > > > > > > > > > > That would be problematic given the signature of this function > > > > > > > and the nature of the potential bug which would most likely b= e a usage error. > > > > > > > > > > > > Of course to handle that, the function's signature need to be c= hanged. > > > > > > Changing it has the advantage that the error handling can be do= ne at the > > > > > > caller, in common code, instead of duplicating it for all > > > > > > architectures, possibly > > > > > > leading to different semantics. > > > > > > > > > > Given that *all* current users of syscall_get_arguments specify i= =3D=3D 0 > > > > > (and there is an architecture that has BUG_ON(i)), > > > > > it should be really a usage error to get into situation where i += n > 6, > > > > > I wish a BUILD_BUG_ON could be used here instead. > > > > > > > > > > I don't think it worths pushing the change of API just to convert > > > > > a "cannot happen" assertion into an error that would have to be d= ealt with > > > > > on the caller side. > > > > > > > > I suggest the following BUG_ON replacement for syscall_get_argument= s: > > > > > > > > #define SYSCALL_MAX_ARGS 6 > > > > > > > > static inline void > > > > syscall_get_arguments(struct task_struct *task, struct pt_regs *reg= s, > > > > unsigned int i, unsigned int n, unsigned long= *args) > > > > { > > > > /* > > > > * Ideally there should have been > > > > * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS); > > > > * instead of these checks. > > > > */ > > > > if (unlikely(i > SYSCALL_MAX_ARGS)) { > > > > WARN_ONCE(1, "i > SYSCALL_MAX_ARGS"); > > > > return; > > > > > > Does this have security implications, as args is an output parameter? > > > I.e. if you don't fill the array, the caller will use whatever is on = the stack. > > > Can this ever be passed to userspace, leaking data? > > > > In the current kernel code n is always less or equal to 6, > > but in theory future changes can potentially break the assertion > > and this could lead to leaking data to userspace. >=20 > OK. >=20 > > Do you think we should rather be defensive and add some memsets, e.g. > > > > if (unlikely(i > SYSCALL_MAX_ARGS)) { > > WARN_ONCE(1, "i > SYSCALL_MAX_ARGS"); > > memset(args, 0, n * sizeof(args[0])); > > return; > > } > > if (unlikely(n > SYSCALL_MAX_ARGS - i)) { > > unsigned int extra =3D n - (SYSCALL_MAX_ARGS - i); > > > > WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS"); > > n =3D SYSCALL_MAX_ARGS - i; > > memset(&args[n], 0, extra * sizeof(args[0])); > > } > > ? >=20 > Yes please. >=20 > But please handle all of that in the generic code, so it doesn't have to = be > replicated across all architectures. >=20 > E.g. make syscall_get_arguments() a wrapper in generic code, calling > __syscall_get_arguments() in architecture-specific code. >=20 > And make the latter return int, so it can indicate other failures. Other failures? What syscall_get_arguments is expected to do if __syscall_get_arguments returned, say, -1? Anyway, as asm-generic/syscall.h is used for documentation purposes only, I can try to prepare it for inclusion in other files without risk of starting a big refactoring that would affect all architectures -- a thing I'd rather not include into this series which is all about adding PTRACE_GET_SYSCALL_INFO API. I suppose there is no rush and arch-specific asm/syscall.h can switch to use asm-generic/syscall.h gradually. --=20 ldv --OwLcNYc0lM97+oe1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJcEPlAAAoJEAVFT+BVnCUIeCgP/Az/LQ6KIH3YJpJeGNYKG3jr oL1Wmo2WROPVFLDRRZPNVA+AhPDPK28Za1eLCZg8oSUzZOn24QbnW0lzGNUeZZ9h PFmUmOFVKlR+fQUqkXesw7o/Cct1NZiuCHJ1x7TXLPLBJUgYCiUunKYYjk5AI006 XBdToz4Q9cWX5q+XMBla6VZc7SYhL10FOClJjW2iF1PfqUSGGMDlXB9RG7ASDSmJ Daz5+6uK/7SoVHcfwYy54ZMmP2hI8XBZo9j/rer/t4BTQffLiiWV6mFuWtnnTbnf IvIeqDBXzsIiFUN0O1XSwytbZhQoMK/7+f6i9xODtRqVwnUQ/fvjD+WcRFi/RP4l HMbZnHS/0daLMYGTiq9yF950WQhvUhIMO77QOEoDgRvEinDk2m4ykawNQDm3Pgd0 HPNV2Gmf3L8ioil6tAO+lW7MX1ThMUmAMZD9Ek5UxW5FZvElv8doSM8/9DS8HoDy eS2WLxW7DjMHZ9ZlsYJP65XqV/FrA7lCn2142N6KmUSRM+oHofRHiSJNdRXgTEYg SMWw9t5i9Fhz5Xzgv2IjwsLDvYRkUJ3SfCytTk+XyCemXP0bYUy8QYmeDNgnwlNz 7+85H5H8i3ff/fLTEVm4pmmuVaOZV+ANFq2jEsT98foxfps+IVbydtnH0zqijI54 RlBevQ3m5gbh5eaXykSR =Ivzb -----END PGP SIGNATURE----- --OwLcNYc0lM97+oe1--