Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5096106rwe; Tue, 18 Apr 2023 01:53:18 -0700 (PDT) X-Google-Smtp-Source: AKy350YuzcZfX0QUxhflXtEuSkClbz9JH6CXLaZPP6xtbhec1FKPtQ8nUO0W/QCugrpUqB6+DygP X-Received: by 2002:a05:6a21:6d94:b0:ef:2389:66ca with SMTP id wl20-20020a056a216d9400b000ef238966camr11026500pzb.7.1681807998076; Tue, 18 Apr 2023 01:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681807998; cv=none; d=google.com; s=arc-20160816; b=WbKCa1mf8iaq35aH7BxcQ4LhARB6Y2PquiaD0FR8URfalgtbmOL06Dw8iuZkR5Doq4 2qM+dS2rGqEIcax4tjXu6AaPSfQLkU1abcrV+aT3WXPkrXrjNK8D6nJxW1Twn3qn2Oso CVRq7Mo217GJszcyMIUSIyb2QMXLWDzzGi07UplOAv22losqQsjHGM5msTQPXmV7vKL9 TwHdIssb8iJ3jhUfFsp5CUIEc7WWT1EmZeuKgTZ5Ji/fiXQBDY7I9VVBhnADU9rlJe6e FkXsZWONiNK4ajVWmcdk6QASVCWzd/2nRytyePHNHFLaD1BUgkIJfvDtQxC7vITY767x DOPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=RH1QL+CMMUftjue/1I+BE+vaXEZ73VCJ4XeV2fk8Lj0=; b=nKb0CrPLrdbsPm7TwtwjfJA4Zt1PoR+4ektMOFEGYtnbtNup9mlZxmnQfT+Nzu5iUH inaUoPKT0nPm97v5LZnIGMQtrtoEmw7LokM/sBRnbnPt93ndWPZ+V7bAzYbWr0u/cG6z JbHSdPUj4GDzJOEdjl3CksbbyyHQDNhXwpgOtNIM+uds3DN5y2GNQHb0x+5hx84Fc3pS 3VUKSLUf/cxB1SHXLLmxBCAtgxU2YzFg6t7sjgRhEy0PVU/WVgCYsG1gMl/sG2j8MEmo Z0AyegtTbpbWIB2zdnTmb5gsUOeh4MO++76aPMay8fLo7xpmP1r6i+boG4BbAaFCGLlp 5Ngg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UUG9NnR4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a6566c5000000b0050bf6a432ecsi10058001pgw.681.2023.04.18.01.53.03; Tue, 18 Apr 2023 01:53:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UUG9NnR4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231311AbjDRIrs (ORCPT + 99 others); Tue, 18 Apr 2023 04:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjDRIrm (ORCPT ); Tue, 18 Apr 2023 04:47:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0635D40CC; Tue, 18 Apr 2023 01:47:40 -0700 (PDT) Date: Tue, 18 Apr 2023 08:47:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681807659; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RH1QL+CMMUftjue/1I+BE+vaXEZ73VCJ4XeV2fk8Lj0=; b=UUG9NnR4yfIvRMs3Bl7FESxzQlE8K8PQIl7CodAVuH1D2N22lrAkq2xTcxBub2Ah8y4VaG ojnoAWR6xKXKTGuGiN55EbsyCx72Uosg595kz1EOixk6sU6fzKwusat6rLO6lffFN8eyXP Bp+1hN0sy2ctn8PR7dcuL1bRX5sVhl9d9E3l1CgBizujN7ob3gR2JTM72CPeQuuKrkm4IZ fFWpPJ9Mgp6nWa2lYBwlzUiA5Xcx9+djpTu+s+fJBgyQalH1UYeoWW15xw1bFNNvhuEn+p COs2+D3d5IlHyh+tp2s3ApFx6mKrvdATYHTcKtBIbomeqFufsHP0c2xK4EehlA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681807659; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RH1QL+CMMUftjue/1I+BE+vaXEZ73VCJ4XeV2fk8Lj0=; b=w0gs+xu7KLm4gvfWZMs/eBzZw8gCYEaeQue47nwrW02woD8LYdpksgrpzJZILeBo/yxQon zCSR6NIBm9TOMMAQ== From: "tip-bot2 for Gregory Price" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: core/entry] syscall_user_dispatch: Untag selector address before access_ok() Cc: Catalin Marinas , Gregory Price , Thomas Gleixner , Oleg Nesterov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230407171834.3558-3-gregory.price@memverge.com> References: <20230407171834.3558-3-gregory.price@memverge.com> MIME-Version: 1.0 Message-ID: <168180765889.404.10655049417638355294.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the core/entry branch of tip: Commit-ID: 463b7715e7ce367fce89769c5d85e31595715ee1 Gitweb: https://git.kernel.org/tip/463b7715e7ce367fce89769c5d85e31595715ee1 Author: Gregory Price AuthorDate: Fri, 07 Apr 2023 13:18:32 -04:00 Committer: Thomas Gleixner CommitterDate: Sun, 16 Apr 2023 14:23:07 +02:00 syscall_user_dispatch: Untag selector address before access_ok() To support checkpoint/restart, ptrace must be able to set the selector of the tracee. The selector is a user pointer that may be subject to memory tagging extensions on some architectures (namely ARM MTE). access_ok() clears memory tags for tagged addresses if the current task has memory tagging enabled. This obviously fails when ptrace modifies the selector of a tracee when tracer and tracee do not have the same memory tagging enabled state. Solve this by untagging the selector address before handing it to access_ok(), like other ptrace functions which modify tracee pointers do. Obviously a tracer can set an invalid selector address for the tracee, but that's independent of tagging and a general capability of the tracer. Suggested-by: Catalin Marinas Signed-off-by: Gregory Price Signed-off-by: Thomas Gleixner Reviewed-by: Catalin Marinas Acked-by: Oleg Nesterov Link: https://lore.kernel.org/all/ZCWXE04nLZ4pXEtM@arm.com/ Link: https://lore.kernel.org/r/20230407171834.3558-3-gregory.price@memverge.com --- kernel/entry/syscall_user_dispatch.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/entry/syscall_user_dispatch.c b/kernel/entry/syscall_user_dispatch.c index 22396b2..7f2add4 100644 --- a/kernel/entry/syscall_user_dispatch.c +++ b/kernel/entry/syscall_user_dispatch.c @@ -87,7 +87,16 @@ static int task_set_syscall_user_dispatch(struct task_struct *task, unsigned lon if (offset && offset + len <= offset) return -EINVAL; - if (selector && !access_ok(selector, sizeof(*selector))) + /* + * access_ok() will clear memory tags for tagged addresses + * if current has memory tagging enabled. + + * To enable a tracer to set a tracees selector the + * selector address must be untagged for access_ok(), + * otherwise an untagged tracer will always fail to set a + * tagged tracees selector. + */ + if (selector && !access_ok(untagged_addr(selector), sizeof(*selector))) return -EFAULT; break;