Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp210638imu; Wed, 12 Dec 2018 15:13:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/WQxY2q0yfjU8HkPfDR7A4CrB2aqQJyDz9xz+SOd+WB+2eV7f9UVCLz7eJQX91MKaPVuzEy X-Received: by 2002:a17:902:8e8b:: with SMTP id bg11mr22012556plb.332.1544656421226; Wed, 12 Dec 2018 15:13:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544656421; cv=none; d=google.com; s=arc-20160816; b=OhBcRwojRWG5Mzx3rauS0+OZC5fY1eqymQ8KJ2fNvoxMzKFZAqi5VVURWAAbm/1kJ3 K3V+u6IAPO1L+zblAzv9NBHi1xWbiwrXBqjR6ZQhle8IyHfF/7bIvzuEgW6MRs3e7D4D BP39Akc3Q8vY4OqUdQY08XGbJBBsRceWHwdiTZ+mCHByypOeACPUBoqCwObuFluKw1gc jizUv2cXWdHu3wz7QjAxDV+jprLEvlrSMbLso87EHmh6GEzSOB0o+TuLs2ik7k50iWBh wYf/bcETpi/un2XKyOSo09f6POKa5t6ND68diyUFDFaAENtBn+RsVSW1BK9Y6dspJhcv mnvA== 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=RZ33mVrJUi5am1M+NGXX7JIqXcDVSdmVsKwIkavwIhA=; b=F+VpNYXS0qbJmckEX1VIkE4D4FXBSxC4dCLap+vLNzYAHqtKb4yrxK8nu4u+MJTXJK XtB+YiBITPa5MFC33G7fuypyAOCMYO2yIlHQVOQFNiAu9tjRQr6A/+ejuM+GNL+wflsH weRuhv4P7+DyHZLpenwmuv1H7KjLHZTTGUfhE52Z9skq+3UP5W2KYSMO5VN3uBO8uF+6 /AvZNMcBdCgvRLTjXAOHalCx6UxiRzu+OUCotw41w6kXUTZ8/bF/Be4ONAZYsR0Q8G5E xSsV8OVbRuNuC8MfOScVsDkP3/K1JexDEOnhkv8jth9oULbgpPC6qqZGgNwJld1JxXtM epeQ== 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 o5si75509plk.360.2018.12.12.15.13.23; Wed, 12 Dec 2018 15:13:41 -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 S1728121AbeLLXMe (ORCPT + 99 others); Wed, 12 Dec 2018 18:12:34 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:53136 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726253AbeLLXMe (ORCPT ); Wed, 12 Dec 2018 18:12:34 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 5E40972CC70; Thu, 13 Dec 2018 02:12:28 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 3A32895D253; Thu, 13 Dec 2018 02:12:28 +0300 (MSK) Date: Thu, 13 Dec 2018 02:12:28 +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: <20181212231228.GA24195@altlinux.org> References: <20181210133025.GG11942@altlinux.org> <20181212085516.GA13288@altlinux.org> <20181212092712.GD13288@altlinux.org> <20181212120417.GC15561@altlinux.org> <20181212123730.GA16479@altlinux.org> <20181212130711.GB16479@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2fHTh5uZTiUOsy+g" Content-Disposition: inline In-Reply-To: <20181212130711.GB16479@altlinux.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --2fHTh5uZTiUOsy+g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Geert, On Wed, Dec 12, 2018 at 04:07:11PM +0300, Dmitry V. Levin wrote: > On Wed, Dec 12, 2018 at 01:54:05PM +0100, Geert Uytterhoeven wrote: > > On Wed, Dec 12, 2018 at 1:37 PM Dmitry V. Levin wrot= e: > > > On Wed, Dec 12, 2018 at 01:27:14PM +0100, Geert Uytterhoeven wrote: > > > > On Wed, Dec 12, 2018 at 1:04 PM Dmitry V. Levin = wrote: > > > > > On Wed, Dec 12, 2018 at 10:43:33AM +0100, Geert Uytterhoeven wrot= e: > > > > > > 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 wrote: > > > > > > > > > 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 Uytterh= oeven wrote: > > > > > > > > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin wrote: > > > > > > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uyt= terhoeven wrote: > > > > > > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <= ldv@altlinux.org> wrote: > > > > > > > > > > > > > > syscall_get_* functions are required to be impl= emented on all > > > > > > > > > > > > > > architectures in order to extend the generic pt= race API with > > > > > > > > > > > > > > PTRACE_GET_SYSCALL_INFO request. > > > > > > > > > > > > > > > > > > > > > > > > > > > > This introduces asm/syscall.h on m68k implement= ing all 5 syscall_get_* > > > > > > > > > > > > > > functions as documented in asm-generic/syscall.= h: syscall_get_nr, > > > > > > > > > > > > > > syscall_get_arguments, syscall_get_error, sysca= ll_get_return_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_argum= ents, syscall_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 pt_regs *regs, > > > > > > > > > > > > > > + unsigned int i, unsigned = int n, unsigned 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 choose > > > > > > > > > > > > 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 th= is function > > > > > > > > > > > > and the nature of the potential bug which would mos= t likely be a usage error. > > > > > > > > > > > > > > > > > > > > > > Of course to handle that, the function's signature ne= ed to be changed. > > > > > > > > > > > Changing it has the advantage that the error handling= can be done 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 ha= ve to be dealt with > > > > > > > > > > on the caller side. > > > > > > > > > > > > > > > > > > I suggest the following BUG_ON replacement for syscall_ge= t_arguments: > > > > > > > > > > > > > > > > > > #define SYSCALL_MAX_ARGS 6 > > > > > > > > > > > > > > > > > > static inline void > > > > > > > > > syscall_get_arguments(struct task_struct *task, struct pt= _regs *regs, > > > > > > > > > unsigned int i, unsigned int n, uns= igned 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 whate= ver 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 assert= ion > > > > > > > and this could lead to leaking data to userspace. > > > > > > > > > > > > OK. > > > > > > > > > > > > > Do you think we should rather be defensive and add some memse= ts, 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])); > > > > > > > } > > > > > > > ? > > > > > > > > > > > > Yes please. > > > > > > > > > > > > But please handle all of that in the generic code, so it doesn'= t have to be > > > > > > replicated across all architectures. > > > > > > > > > > > > E.g. make syscall_get_arguments() a wrapper in generic code, ca= lling > > > > > > __syscall_get_arguments() in architecture-specific code. > > > > > > > > > > > > And make the latter return int, so it can indicate other failur= es. > > > > > > > > > > Other failures? What syscall_get_arguments is expected to do > > > > > if __syscall_get_arguments returned, say, -1? > > > > > > > > Fail. Just like in case of other generic ill conditions it can dete= ct itself. > > > > > > Sorry, I don't quite follow. syscall_get_arguments() has no return c= ode, > >=20 > > Which may be an indicator for a different problem. > > What is e.g. populate_seccomp_data() supposed to do if > > syscall_get_arguments() fails? >=20 > Well, syscall_get_arguments() is not supposed to fail if invoked properly. >=20 > Currently populate_seccomp_data() does this: > struct task_struct *task =3D current; > struct pt_regs *regs =3D task_pt_regs(task); > unsigned long args[6]; > ... > syscall_get_arguments(task, regs, 0, 6, args); >=20 > I don't see how this could fail. >=20 > > > so all it can possibly do is to zero out args[], e.g. > > > > > > if (unlikely(__syscall_get_arguments(task, regs, i, n, args) = < 0)) { > > > memset(args, 0, n * sizeof(args[0])); > > > return; > > > } > > > > > > Do you mean this? > >=20 > > Exactly. >=20 > OK, I'll prepare the change, thanks. I have the change ready, but I don't like it. The only architecture that could benefit from being able of signalling an error condition to syscall_get_arguments is MIPS, and even in that case the return code is not suitable because it wouldn't help to distinguish between the first 4 syscall arguments that cannot cause an error and remaining arguments that can. It looks like there is no need to make __syscall_get_arguments() to return int after all. --=20 ldv --2fHTh5uZTiUOsy+g Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJcEZXbAAoJEAVFT+BVnCUIZ6MQAI484glw6id/flu/J6HanrXH YXyZ0SktJchbsonGJqf5X1yCXfRcEpqqYcTsiibcEoPgvcTtB9643qZj+H7HloC8 BgxbgUxpNRt7t/xUKf/ezRk7qPw/XvuJo7mTjj1uAOCWR6Br5Cza5U9CnOglOh0q LTlZ1G1/+5O20KbCZfihON1dHdsOAUaplWEPz3fzpKXKsreI46p0LIQfgOF414J4 npHEOJl/317DecKtsjVHwMaP3mGeFzmuYkHvv2iVPArjXVUi1amJhEHMTs6UKgGZ gknWIj9y4f1x2me30ayd7YMDRdA4+3+aoJh/xLQDWdBVwOPRGbUkaUq0bW5u6Iit Bmk7tLufiPEnDmoTqpbVTjdXghifK5V9YbyUuY4zJKbi7g6HKv6ldW6BvNgg6Wpc U5MKZN6cUIR8dadJXurifEF95V0oSbP1J0RlWF8a/JtVHcfNazKwra0XKwWXqjhZ OucdBsZuZ1m+3dZZLRUzEqOQySQhppOPYhtc461ksZTRY2EIo1w4v+W/ggBzcNjO p/OTdn0Ptck+6gjuUGKm/SuMOKS9rQGLCvcyLxk4DiyJDLCsgOmpvBw7Ybc47exF dQBfCpptXeUDKvLuKyLxC9xVQy/Hn8SEf/PXC0DQMIvFVB03+d28zZ5kBK//rWu4 QVRdxvUH11qU0lE9iVj1 =Ja5k -----END PGP SIGNATURE----- --2fHTh5uZTiUOsy+g--