Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1690203pxb; Mon, 22 Feb 2021 08:30:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxm1oE7BzRd++5Ur+xG9d4ka6QmtcvgGFPCDkzytlhxTBp0uD0xPYhF3Gz4wRch0vitZjAb X-Received: by 2002:a05:6402:5243:: with SMTP id t3mr23245098edd.361.1614011408101; Mon, 22 Feb 2021 08:30:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614011408; cv=none; d=google.com; s=arc-20160816; b=HC7JrnuG/VeRqFmnQ/QPbtXvD/x8lyqIrPYsU4DWhjjeCmbtaH1e3jeknTpzyHWMgH zAjQ7V5DbyzdaIRk/AZpiCFEiPH1nd368T/OXC7Mrp6cee/TFJ6T+YDda+t9/k3iHwRw hJML6G8FS91C7UD7UU3zxaPf5qEg03BhPMGh+n0EJcTaiqXBXsjXQrlfs/qQYvW6QGiX ujiGHRBQMdHh3hQGO+7BgSYNyDe146izF1ELr/ipzIhslHdES277k/RGDwZasiizsMjM gUwS/R9sWd0a4hKDfLj63HittkQ945q1pcTZSmmHWzk4I37AQBExTgkvkKyc7P4v3+jx J3tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hxJY4gXSRgdPlLvI81tzml7fLabj700XDSj9osY1/o8=; b=x9P/gtaqeI+0GSmicWgl+g0ASoEkKuWry1Z4DiV0CzJYbtbJmtxLxYvNdyrcAGoJG4 duvDW6UOOLOWI7P+NRGPi23fwkoGDjbKaY2gXFmefb2FK644GSQBTso4sNmCnGc4WUN/ z+j0TKzJfR67e1PxDYAmMI4GsBhJ/yhya2RHf7knep0Gj4IsWM+QKqotl0eYaT9w+dGj 93WZlNAAKE7WIrnkL70rkkox1SyZaZZFobwxQRNXH+rye5wMyxRU+wAqVMlNefDCsOjH fOaW49rrx8Ep/EiJJUmld/OalAb3+XEFoFaH3tpMRBxGqi5JCxilH13Zk+t9J3/37iQp 7rkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si13871437ejr.734.2021.02.22.08.29.44; Mon, 22 Feb 2021 08:30:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231243AbhBVQ0m (ORCPT + 99 others); Mon, 22 Feb 2021 11:26:42 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:50954 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbhBVQZx (ORCPT ); Mon, 22 Feb 2021 11:25:53 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 967FB72C8B3; Mon, 22 Feb 2021 19:25:05 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 86F107CC89C; Mon, 22 Feb 2021 19:25:05 +0300 (MSK) Date: Mon, 22 Feb 2021 19:25:05 +0300 From: "Dmitry V. Levin" To: Mathieu Desnoyers Cc: Piotr Figiel , Andrew Morton , Peter Zijlstra , paulmck , Boqun Feng , Oleg Nesterov , Alexey Dobriyan , Andrei Vagin , linux-kernel , Peter Oskolkov , Kamil Yurtsever , Chris Kennelly , Paul Turner , emmir@google.com, linux-man , linux-api Subject: Re: [PATCH] ptrace: add PTRACE_GET_RSEQ_CONFIGURATION request Message-ID: <20210222162505.GB1325@altlinux.org> References: <20210222100443.4155938-1-figiel@google.com> <20210222115726.GA30843@altlinux.org> <1510231959.29418.1614005590596.JavaMail.zimbra@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1510231959.29418.1614005590596.JavaMail.zimbra@efficios.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 22, 2021 at 09:53:10AM -0500, Mathieu Desnoyers wrote: > ----- On Feb 22, 2021, at 6:57 AM, Dmitry V. Levin ldv@altlinux.org wrote: > > On Mon, Feb 22, 2021 at 11:04:43AM +0100, Piotr Figiel wrote: [...] > >> +#ifdef CONFIG_RSEQ > >> +static long ptrace_get_rseq_configuration(struct task_struct *task, > >> + unsigned long size, void __user *data) > >> +{ > >> + struct ptrace_rseq_configuration conf = { > >> + .rseq_abi_pointer = (u64)(uintptr_t)task->rseq, > >> + .signature = task->rseq_sig, > >> + }; > >> + > >> + size = min_t(unsigned long, size, sizeof(conf)); > >> + if (copy_to_user(data, &conf, size)) > >> + return -EFAULT; > >> + return size; > >> +} > >> +#endif > > > > From API perspective I suggest for such interfaces to return the amount of > > data that could have been written if there was enough room specified, e.g. > > in this case it's sizeof(conf) instead of size. > > Looking at the ptrace(2) man page: > > RETURN VALUE > On success, the PTRACE_PEEK* requests return the requested data (but > see NOTES), the PTRACE_SECCOMP_GET_FILTER request returns the number of > instructions in the BPF program, and other requests return zero. PTRACE_GET_SYSCALL_INFO returns "the number of bytes available to be written by the kernel". It's written in the "DESCRIPTION" section, needs to be mirrored to "RETURN VALUE" section, thanks for reporting the inconsistency. > On error, all requests return -1, and errno is set appropriately. > Since the value returned by a successful PTRACE_PEEK* request may be > -1, the caller must clear errno before the call, and then check it af‐ > terward to determine whether or not an error occurred. > > It looks like the usual behavior for ptrace requests would be to return 0 when everything > is OK. Unless there a strong motivation for doing different for this new request, I > would be tempted to use the same expected behavior than other requests on success: > return 0. > > Unless there is a strong motivation for returning either size or sizeof(conf) ? If we > return sizeof(conf) to user-space, it means it should check it and deal with the > size mismatch. Is that size ever expected to change ? When adding new interfaces, it's generally a good idea to allow for future extensions. If some day in the future the structure is extended, the return value would be the way to tell userspace what's actually supported by the kernel. -- ldv