From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4A684C0414 for ; Thu, 2 Jul 2026 09:58:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782986309; cv=none; b=G3D0HHib4qwPP+cB7UmFLc67bHhX4HErdgWgtweDmviFE1vM/JLdoQTpbbLKYKL3Kfcxk8pBD7lPcX2BDI7fTc9jV2VhwpGlm5+ozUVaRgAOkxQDBu1cpLKZMb+wcwjhBkQgoWSxtMHg0qAS3uQfxn6eqNSCXeEWSDdWs3lSvCc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782986309; c=relaxed/simple; bh=9uZoM1v36zUKVcX7nVNvPN/f9YnP7D5j2+rFSeuNQEg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=avt8mEvP5dDguk6YYKYJuQPMe6xUbChhLH96xOfuxwoVytnnxorsBS+Au7cr0Dx32qnGBtJjMrAB0drgHR80V2o9pnf7WiKwroCnqbN1HDxTjimx20hZ1YXcZALQIc8mrYpPpSyd0U5Ibotq0C3jMoIfhrb29sTG4+WccRly6O0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=E2kfSlDB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E2kfSlDB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782986306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gYaKTKDrGGML994i+eDqXFi18VHa40seBP1nWlJHLG0=; b=E2kfSlDB32HY2PSdT3GXIoA3T1Fs79LLSTyC2JrpTDJ/nokaMFma4MBvNlLsf77EVz7Yer gX4CpHJt2z6E1hjb9X9Hy6TP/3d+gBzk1FdkCYI6fQEZMQtrltht7cC5D2rD410i6PRrZQ MHMrMccaFFysQOoROzUZkZv54TWv8Yk= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-vIcSrjfVPIyohW1ZAmTqKQ-1; Thu, 02 Jul 2026 05:58:23 -0400 X-MC-Unique: vIcSrjfVPIyohW1ZAmTqKQ-1 X-Mimecast-MFC-AGG-ID: vIcSrjfVPIyohW1ZAmTqKQ_1782986302 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D421B18C0FF7; Thu, 2 Jul 2026 09:58:20 +0000 (UTC) Received: from fedora (unknown [10.44.32.200]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id E42FE196B0A5; Thu, 2 Jul 2026 09:58:16 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 2 Jul 2026 11:58:20 +0200 (CEST) Date: Thu, 2 Jul 2026 11:58:14 +0200 From: Oleg Nesterov To: Renzo Davoli Cc: linux-kernel@vger.kernel.org, Andrew Morton , Shuah Khan , Alexey Gladkov , Eugene Syromyatnikov , Mike Frysinger , Davide Berardi , strace-devel@lists.strace.io, Dmitry Levin Subject: Re: [PATCH 1/5] ptrace: add PTRACE_SYSCALL_INFO_SECCOMP_SKIP Message-ID: References: <20260701150558.330348-1-renzo@cs.unibo.it> <20260701150558.330348-2-renzo@cs.unibo.it> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 On 07/02, Renzo Davoli wrote: > > Hi Oleg, > > > Rather than add the new PTRACE_SYSCALL_INFO_SECCOMP_SKIP, can't we teach > > ptrace_set_syscall_info_seccomp() to treat info->entry.nr == -1 as "skip" ? > it already does > > Note that ptrace_set_syscall_info_seccomp() -> ptrace_set_syscall_info_entry() > > already does syscall_set_nr(). > Syscall skipping is useless if there is not a way to set the return value/errno. > > As I explain in the cover letter > + The tracer can skip the system call by setting the system call number > + to -1. However, the current PTRACE_SET_SYSCALL_INFO interface does not > + provide a way to specify the return value or error code that should be > + reported to the tracee after skipping the call. > > currently retvalue/errno can be set only at PTRACE_SYSCALL_INFO_EXIT I meant something like below. This way both PTRACE_SYSCALL_INFO_ENTRY and __SECCOMP can skip the syscall and set the return/errr value. Oleg. --- diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h index 5f8ef6156752..4ee7870f3291 100644 --- a/include/uapi/linux/ptrace.h +++ b/include/uapi/linux/ptrace.h @@ -90,7 +90,13 @@ struct ptrace_syscall_info { union { struct { __u64 nr; - __u64 args[6]; + union { + __u64 args[6]; + struct { + __s64 rval; + __u8 is_error; + }; + }; } entry; struct { __s64 rval; diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 130043bfc209..1daac0e62cfa 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -1031,6 +1031,28 @@ ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size, return copy_to_user(datavp, &info, write_size) ? -EFAULT : actual_size; } +static int +__set_syscall_info_exit(struct task_struct *child, struct pt_regs *regs, + __s64 __rval, __u8 __is_error) +{ + long rval = __rval; + + /* + * Check that the return value specified in info->exit.rval + * is either a value of type "long" or a sign-extended value + * of type "long". + */ + if (rval != __rval) + return -ERANGE; + + if (__is_error) + syscall_set_return_value(child, regs, rval, 0); + else + syscall_set_return_value(child, regs, 0, rval); + + return 0; +} + static int ptrace_set_syscall_info_entry(struct task_struct *child, struct pt_regs *regs, struct ptrace_syscall_info *info) @@ -1047,6 +1069,11 @@ ptrace_set_syscall_info_entry(struct task_struct *child, struct pt_regs *regs, if (nr != info->entry.nr) return -ERANGE; + syscall_set_nr(child, regs, nr); + if (nr == -1) + return __set_syscall_info_exit(child, regs, + info->entry.rval, info->entry.is_error); + for (i = 0; i < ARRAY_SIZE(args); i++) { args[i] = info->entry.args[i]; /* @@ -1058,16 +1085,7 @@ ptrace_set_syscall_info_entry(struct task_struct *child, struct pt_regs *regs, return -ERANGE; } - syscall_set_nr(child, regs, nr); - /* - * If the syscall number is set to -1, setting syscall arguments is not - * just pointless, it would also clobber the syscall return value on - * those architectures that share the same register both for the first - * argument of syscall and its return value. - */ - if (nr != -1) - syscall_set_arguments(child, regs, args); - + syscall_set_arguments(child, regs, args); return 0; } @@ -1086,22 +1104,8 @@ static int ptrace_set_syscall_info_exit(struct task_struct *child, struct pt_regs *regs, struct ptrace_syscall_info *info) { - long rval = info->exit.rval; - - /* - * Check that the return value specified in info->exit.rval - * is either a value of type "long" or a sign-extended value - * of type "long". - */ - if (rval != info->exit.rval) - return -ERANGE; - - if (info->exit.is_error) - syscall_set_return_value(child, regs, rval, 0); - else - syscall_set_return_value(child, regs, 0, rval); - - return 0; + return __set_syscall_info_exit(child, regs, + info->exit.rval, info->exit.is_error); } static int