Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1650759imu; Wed, 12 Dec 2018 01:45:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/XayFGcatPBP7BARPWd0D2epgTNKFY1Y7pvJ5kLJarUkioV9JbNmOYhoP1vYPLJiijDTOaJ X-Received: by 2002:a17:902:9305:: with SMTP id bc5mr18996987plb.86.1544607922349; Wed, 12 Dec 2018 01:45:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544607922; cv=none; d=google.com; s=arc-20160816; b=jsqlWjIMBOMRIQniOmWCSZ113rHDK+X3agowXdrs8vCfhUluObd8SNvFmbzMVsga4g YfrNdZXNBkNgC7iE6hl76zMn3nQMFltZqrqAjkoz/SnSHqJcgLbyagy0aWd59wE+YCP2 WpUIKm96Eek6mEllNOW36CX1dPS/XCYpUOYcuEYnkN/83n9Y/WmFyliJ0CujSYKQ1p1u dQ4ZjjIGyLSt7uoVPoUBhd5vjTzzP8mwMpyCJCuuDjR8EValcReyyv2wFHDlU1jWvNZB Pn2BFfsKE5aJn+lCscrBV1eJvTVJK6U0ClstZZScR9JFzR1pngXLTZr2cNhYeCJw+8ii vksA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=bdLHCAfRE+sBCvf6vaPC8sAhl9WaqSS5fAni2sVkOYM=; b=y3Xo8O0bTY5uD2680AOlz6USSoHJ0EvSguWtMY1kjqKEVSJcGAKfwtwjOqBePFmm9q QKBRFr1G/QfvUaKEwnJt9Biyz+p0cIrumQ/mFWt9TMgwSooihOT3o4D/wfIWyZGJ5ya6 gR3vQS+OZ+XoUeRYPEKwPPTvEjlgSqjOnFH1qA3h4oV4ruej7txmTCK2cDFKB/cnnBOl VN9lWNxUbR+iXU5xZrpAIfF2dMMELeR1f870z5wtRl3xpBhUEkJkjlBNGGCpq+h4dsZz fnOx5D1iEobxHliDTO6nd6TL3Olk8uk+OzeYv20ZU137qCkeBxO+TebbzjUAzmXfzgFW 5ubw== 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 35si15767598plf.177.2018.12.12.01.45.05; Wed, 12 Dec 2018 01:45: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 S1726896AbeLLJns (ORCPT + 99 others); Wed, 12 Dec 2018 04:43:48 -0500 Received: from mail-vk1-f195.google.com ([209.85.221.195]:45647 "EHLO mail-vk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbeLLJns (ORCPT ); Wed, 12 Dec 2018 04:43:48 -0500 Received: by mail-vk1-f195.google.com with SMTP id n126so4060737vke.12 for ; Wed, 12 Dec 2018 01:43:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bdLHCAfRE+sBCvf6vaPC8sAhl9WaqSS5fAni2sVkOYM=; b=frSES10eEKr/GXu7xLmiVd5vI4+dEtHEZiOW2VRQSBl/+xVgHkpcyg/rOGz4jJAEHC TTvT97nG/6/NeNC6xm9Uv4rNJT+FVD8uRVIT6Z9yRAYDJfosHt62txGt6WjhpbkTIhtW UwKMmghqhaonX3cImzRlBAeGwKKPulYH6rrInFzgflQBToDUGenvDdPD1YWkUugIJnhI iUE8dQnMd20eUrxitcqjPojE8P2XvEgumuXeI1KVagXYYAM1yjVQijBUsIKCl3UT/HHq bYjQ05CM2kzZJpWwMHFnmEppzafTn6frazwPe2yPD3GoijXrgBPHBTCxGJ+JxjexqSac HNjA== X-Gm-Message-State: AA+aEWbSzCCPR9gf80XR9T0SwdoklU74rFHzkWxaI+X3q2Ds4c0+a/hs pINUUaDKXm3BCFRT0g9kK4rM30UWteDPUrv37xk= X-Received: by 2002:a1f:91cb:: with SMTP id t194mr8930719vkd.74.1544607826192; Wed, 12 Dec 2018 01:43:46 -0800 (PST) MIME-Version: 1.0 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> In-Reply-To: <20181212092712.GD13288@altlinux.org> From: Geert Uytterhoeven Date: Wed, 12 Dec 2018 10:43:33 +0100 Message-ID: Subject: Re: [PATCH v5 13/25] m68k: add asm/syscall.h To: "Dmitry V. Levin" Cc: Oleg Nesterov , Andy Lutomirski , lineprinter@altlinux.org, Eugene Syromiatnikov , linux-m68k , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dmitry, 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 Uytterhoeven 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 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 with > > > > > > > > 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_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_arguments, 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 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 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 == 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 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_regs *regs, > > > 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. 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 = n - (SYSCALL_MAX_ARGS - i); > > WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS"); > n = 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, calling __syscall_get_arguments() in architecture-specific code. And make the latter return int, so it can indicate other failures. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds