Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1828985imu; Wed, 12 Dec 2018 05:10:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/WeqHej5IGA8KqIqMYpDK7Ctt2bHqBKqN7NEFGYzglSLXvtdsgI7IVJ84UBrvyj3oHIEZFE X-Received: by 2002:a62:69c4:: with SMTP id e187mr20391463pfc.50.1544620222099; Wed, 12 Dec 2018 05:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544620222; cv=none; d=google.com; s=arc-20160816; b=MY09z1qtpcR3vBGBUJruuflUhPZVBwbfUgf0ZGtqsxc3SWAU5Kq9R+CkFge007iN/7 osKHeXO+kFbNiLIwniVnCGcjl707WfXIkcU+gRjTkENjjUSuqc6aVUbYnZ0UuXK/QKok dald/3JU564LVebXRaiEbI6z+PK3kaE1CR0X2q6LyJC0/zXCJNTKkPzu4RI0ABOJZ/V9 CQ0ZOsyA1iB+eqdOM+ct3pKI/QftiYMbJbdtgSFUaFnhTIU4cdj6QVobFtUarNC3QRKB NrsFaBfxGTExXpw3qWlGSkkFSSr7zhXDQ01neZl4vxBquL3A8Vv6mOZCSByeZ+RGg4Qy tnoQ== 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=IeegprrFPmVz2iPlrRmpz1SSkljm9fXV/PtolW6g5wA=; b=rmhsIcp95aguzg6CRqBaAvKBB6sitiN4PUn6HoRJ3vM323556JhRdQ4x8dkHjK4IXu GWFKZp6h2G5UeYw1tbKHBMg9Y/KdbOyLlL82VUF4ooe88CARpeQLExZTdp4ROANUdcNm zOuBtPnqHlw2y7eEu7ARKqalEH7DXkd/RGc1MlGBwmbGz4gQyUefXWT+FEFxi87HcBt/ 3H64WP0n8TnvtLBcv7ZsKXn5UbuOa8Qkm3G65lTDbBA5sw1o79NM+uF80D4RRQogU5EZ d5RHWEer4Ee6DiiBMDI0xIzZ7L8SOT40IcLdlxjhVrr0M2zLcR0vzUc0hZ6DZXuGBMRt 2Mrw== 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 i9si15186779plb.35.2018.12.12.05.10.07; Wed, 12 Dec 2018 05:10:22 -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 S1727588AbeLLNH3 (ORCPT + 99 others); Wed, 12 Dec 2018 08:07:29 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:59904 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727544AbeLLNHN (ORCPT ); Wed, 12 Dec 2018 08:07:13 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 7D3B372CA65; Wed, 12 Dec 2018 16:07:11 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 71A907CFF89; Wed, 12 Dec 2018 16:07:11 +0300 (MSK) Date: Wed, 12 Dec 2018 16:07:11 +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: <20181212130711.GB16479@altlinux.org> References: <20181210133025.GG11942@altlinux.org> <20181212085516.GA13288@altlinux.org> <20181212092712.GD13288@altlinux.org> <20181212120417.GC15561@altlinux.org> <20181212123730.GA16479@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1LKvkjL3sHcu1TtY" 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 --1LKvkjL3sHcu1TtY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Geert, 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 wrote: > > 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 wr= ote: > > > > 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 wr= ote: > > > > > > > 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 w= rote: > > > > > > > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoe= ven 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 Uytte= rhoeven wrote: > > > > > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin wrote: > > > > > > > > > > > > > syscall_get_* functions are required to be implem= ented on all > > > > > > > > > > > > > architectures in order to extend the generic ptra= ce API with > > > > > > > > > > > > > PTRACE_GET_SYSCALL_INFO request. > > > > > > > > > > > > > > > > > > > > > > > > > > This introduces asm/syscall.h on m68k implementin= g all 5 syscall_get_* > > > > > > > > > > > > > functions as documented in asm-generic/syscall.h:= syscall_get_nr, > > > > > > > > > > > > > syscall_get_arguments, syscall_get_error, syscall= _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_argumen= ts, 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 in= t 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 c= ould 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 this= function > > > > > > > > > > > and the nature of the potential bug which would most = likely be a usage error. > > > > > > > > > > > > > > > > > > > > Of course to handle that, the function's signature need= to be changed. > > > > > > > > > > Changing it has the advantage that the error handling c= an be done at the > > > > > > > > > > caller, in common code, instead of duplicating it for a= ll > > > > > > > > > > architectures, possibly > > > > > > > > > > leading to different semantics. > > > > > > > > > > > > > > > > > > Given that *all* current users of syscall_get_arguments s= pecify 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 w= here 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 dealt with > > > > > > > > > on the caller side. > > > > > > > > > > > > > > > > I suggest the following BUG_ON replacement for syscall_get_= arguments: > > > > > > > > > > > > > > > > #define SYSCALL_MAX_ARGS 6 > > > > > > > > > > > > > > > > static inline void > > > > > > > > syscall_get_arguments(struct task_struct *task, struct pt_r= egs *regs, > > > > > > > > unsigned int i, unsigned int n, unsig= ned 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 pa= rameter? > > > > > > > I.e. if you don't fill the array, the caller will use whateve= r 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. > > > > > > > > > > OK. > > > > > > > > > > > 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])); > > > > > > } > > > > > > ? > > > > > > > > > > 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, call= ing > > > > > __syscall_get_arguments() in architecture-specific code. > > > > > > > > > > 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? > > > > > > Fail. Just like in case of other generic ill conditions it can detect= itself. > > > > Sorry, I don't quite follow. syscall_get_arguments() has no return cod= e, >=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? Well, syscall_get_arguments() is not supposed to fail if invoked properly. 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); I don't see how this could fail. > > 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. OK, I'll prepare the change, thanks. --=20 ldv --1LKvkjL3sHcu1TtY Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJcEQf/AAoJEAVFT+BVnCUIlPgQAMGAtI7/42vOKKr/xEQt9okf 3l3K2+wmWCycpBuf1ikUE3qUtCNP2wZoY5AlvCI4MYOQ0AojM46Ijrvm/Uyflkyt HY9W13ojdKnGnZ6Sj04YIhrmoDr0EIl5t4LqM8+C7ZXRw4nCKuUCPZTaAcWNTGF1 iSlgPuuBs+8wJkyaZX0flZV4RGQsXasVuxsKx+/hqW+cRBny9Jb5EmcDhf7vwmUR O8r8SEve2ml3lXW6/1QKyt4VzpeXVALleMp9e+uyIz41cU+oD1YB8U6hrICopo/V StDqgBgCSMyobyDXj6OXerv03swM5xV/rl5XT+p/C6uxjNqSOvnPv9N1Fy+YcYSj 65wIz9LXD3Z6mIZeQtoNLCXP1oSCr8Xz7RpbkECU5ecDv/C0ybqJ57wYTav0o6re T3SFYQ/uJVG8Y17jmZVlp5ri7xX0BSdhaT7xdvOv2HGz/TIrcOh1T3YTlPiZtrie qqWmw6AEVg4XgTXZ6GuZ9SHI41+8TohMUnZb/P4SX77WWkmX2zl6txyIH2E4tvRM re7WOGFdTza7aqBDVSbXgfub7pI3xA1No75wYjvR494/HaBeX3ntceqYQqwNiOW2 Sm0w2RlD3qHfcmj0zINjeNCSX3VsPPFgUuIeAcekbt8LctEgRfWTKTl9k1X7B1lQ cAedCEzz+vjkM62Zt5hO =5oRj -----END PGP SIGNATURE----- --1LKvkjL3sHcu1TtY--