Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp881769pxk; Thu, 17 Sep 2020 20:13:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/qAosSBSKTOYW3VA+0tCionoaFUzqZJqzbjqMU5ID9ukrrVFEB3ezTT7/b7vZUxEk8s/J X-Received: by 2002:a50:e79c:: with SMTP id b28mr37259508edn.371.1600398810867; Thu, 17 Sep 2020 20:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398810; cv=none; d=google.com; s=arc-20160816; b=H84xl556qebyrUA60SZiSyWncO/zP8eDtBhV5SqmStLEtPk+qfvo4RuoL10eePfEG3 jdT5JLVTPaWvD1l3iu1P2MsPcYqpcpsq8iMT7Ba5y7nTSUsneebutxGq0qwNcD+5RqQK 4HWf1zNOwqnkEjPjPoOrF/e+5bvTfJYkvXBQ0dknZkIw8kg+SzDGgx7qDCpaw9rQGld/ arJ66nw8kzBk4DPo2qnf+7R2cQ64B41U+S0nXXvU1YrErxvJT726Uk7NgKgzd4Om1hHJ UUh8i6WgeOtqqtCoQYW6OCpT69AY/crO6nQ9JCR1RhNLuI5tpJTPmcgLx1NfkwGlowPl BkLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JST6B5XTc6tURWkDIUSPxalL914OSqO7nUlEKc+NAa0=; b=QsbqFE8daT0n4t3fk21GSE4+soNUppDJr3I7vpEySgDnBHzpWsiMLjDw2JDKzORv5X dP8D8gyIlPKI0Vy3zejnIDGwh+8RBmL3XfVAkTX5/xkX+XumV7D+yJQkpV81yapqasA5 InJ5JwHNZlY6fBhUGE3YQXaewPJCXSHWkPRwlcDxjjcVMbspv+Mf39zKNdTV34IOBYt/ K9UFJj+CBjTJj3NxndgmINkKijzWB7uBsnOxIpN5y4jqv3yH1yFt7cWDmHqQUzYe0o4C YHea52oz1KU6sVBRUR8UsE2cJv0UgxMi1kQz14Z39qODahwxOC/umVfoH+5qOLPpHas/ 8PWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TjgOpr9c; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p26si1282332ejf.86.2020.09.17.20.13.07; Thu, 17 Sep 2020 20:13:30 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=TjgOpr9c; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727266AbgIRDLW (ORCPT + 99 others); Thu, 17 Sep 2020 23:11:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:47710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726755AbgIRCCa (ORCPT ); Thu, 17 Sep 2020 22:02:30 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 11F8921734; Fri, 18 Sep 2020 02:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394549; bh=aBFx1KcBL6iJWVBlTWXIiK8c5LFnK4N15P9qCKDqaGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TjgOpr9cs9iGXrLnfqr5TjNZQcIXQr1+qHLrd5Hc4enl8KKpeUh4N3yj0pESMVwM4 zEx1kRzaois6XnlaLu34M7sgZGNHzX6Fy8n8yQaD+qL0pztbbF0SQmfW5AfwNFL6J7 bqUNozc3+jmV5i0LG1BRbuGWJcQHeh3yHmSt9e8E= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Max Filippov , Sasha Levin , linux-xtensa@linux-xtensa.org Subject: [PATCH AUTOSEL 5.4 066/330] xtensa: fix system_call interaction with ptrace Date: Thu, 17 Sep 2020 21:56:46 -0400 Message-Id: <20200918020110.2063155-66-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Max Filippov [ Upstream commit 02ce94c229251555ac726ecfebe3458ef5905fa9 ] Don't overwrite return value if system call was cancelled at entry by ptrace. Return status code from do_syscall_trace_enter so that pt_regs::syscall doesn't need to be changed to skip syscall. Signed-off-by: Max Filippov Signed-off-by: Sasha Levin --- arch/xtensa/kernel/entry.S | 4 ++-- arch/xtensa/kernel/ptrace.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/arch/xtensa/kernel/entry.S b/arch/xtensa/kernel/entry.S index 59671603c9c62..1f07876ea2ed7 100644 --- a/arch/xtensa/kernel/entry.S +++ b/arch/xtensa/kernel/entry.S @@ -1897,6 +1897,7 @@ ENTRY(system_call) mov a6, a2 call4 do_syscall_trace_enter + beqz a6, .Lsyscall_exit l32i a7, a2, PT_SYSCALL 1: @@ -1911,8 +1912,6 @@ ENTRY(system_call) addx4 a4, a7, a4 l32i a4, a4, 0 - movi a5, sys_ni_syscall; - beq a4, a5, 1f /* Load args: arg0 - arg5 are passed via regs. */ @@ -1932,6 +1931,7 @@ ENTRY(system_call) s32i a6, a2, PT_AREG2 bnez a3, 1f +.Lsyscall_exit: abi_ret(4) 1: diff --git a/arch/xtensa/kernel/ptrace.c b/arch/xtensa/kernel/ptrace.c index b964f0b2d8864..145742d70a9f2 100644 --- a/arch/xtensa/kernel/ptrace.c +++ b/arch/xtensa/kernel/ptrace.c @@ -542,14 +542,28 @@ long arch_ptrace(struct task_struct *child, long request, return ret; } -void do_syscall_trace_enter(struct pt_regs *regs) +void do_syscall_trace_leave(struct pt_regs *regs); +int do_syscall_trace_enter(struct pt_regs *regs) { + if (regs->syscall == NO_SYSCALL) + regs->areg[2] = -ENOSYS; + if (test_thread_flag(TIF_SYSCALL_TRACE) && - tracehook_report_syscall_entry(regs)) + tracehook_report_syscall_entry(regs)) { + regs->areg[2] = -ENOSYS; regs->syscall = NO_SYSCALL; + return 0; + } + + if (regs->syscall == NO_SYSCALL) { + do_syscall_trace_leave(regs); + return 0; + } if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) trace_sys_enter(regs, syscall_get_nr(current, regs)); + + return 1; } void do_syscall_trace_leave(struct pt_regs *regs) -- 2.25.1