From patchwork Tue Apr 18 08:47:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 84687 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2688008vqo; Tue, 18 Apr 2023 01:53:51 -0700 (PDT) X-Google-Smtp-Source: AKy350aV2qA8sEeXTXDbU5/CFnPYgKo6sH2mL+rvx+KlCXoFAIehq74C5ufs5GQuc1/60ADpwOSZ X-Received: by 2002:a05:6a20:6a10:b0:f0:752a:127a with SMTP id p16-20020a056a206a1000b000f0752a127amr3257840pzk.46.1681808031583; Tue, 18 Apr 2023 01:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681808031; cv=none; d=google.com; s=arc-20160816; b=K0SdGoX0S8L86yC+xsZAWpKbwPssQBagTWUIf1GGCXWlZkzvDY6aIvShc2z3Awj+qa yDBiaaMXuCEYSj5JKWBc/9itnnNSDQoleP7EE7Q7XBSVkQMBbqJqlg83DtZyEklynx0x NbuZCI8xtCof82JBMietCVB4ukYMyTjGzftTY85eTYtr+EToFpPP5idFs5alST+UeGg2 dIVAOEX5HleVKO+GRylwKWvj/sVSeokgkqNVzBBc0Lqskd+7c5nJbM9MsSP0AAd7yMG2 zJef5ytSYrJy6M0ogkaxip0EcEbwwGjOgCM4iFucFayHGqSVKxhX7heVBthokQ35le6U NyrQ== 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.b=w0gs+xu7; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c11-20020a63da0b000000b00513a68ca71asi14213595pgh.742.2023.04.18.01.53.36; Tue, 18 Apr 2023 01:53:51 -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.b=w0gs+xu7; 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 S230490AbjDRIrs (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763503538310251718?= X-GMAIL-MSGID: =?utf-8?q?1763503538310251718?= 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;