Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2184540imm; Thu, 23 Aug 2018 16:01:38 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxX8BEFa83x/uZRuebwp2jx79+ahf5NC08s8FCah9sOHa9EWUvSrrs63QcG1n87uTaL3q1V X-Received: by 2002:a62:8a4f:: with SMTP id y76-v6mr64669926pfd.233.1535065298510; Thu, 23 Aug 2018 16:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535065298; cv=none; d=google.com; s=arc-20160816; b=UPq7ovwwACuxzp2YoWw6WXEZW/ACPbId3P+ODh2GyHMqFkCkIieaLhEGD1EA7F1MOs DYhuqA4gpBMoe8GlcRv8ZpSEcNXfoK7cArG1WpmdIV2xsMSov9iatp6byyo6/QLZ8VIE QMLvWwzx7qpzs0VDakjzJdL5ndzT5bV+KlTNXtP0f0/zuuTA/Z1Fs3rS/IkmUFhgMDc2 MTxNnctg6ZRZaTdER3d5KeXKqkmlqX16qgDPXq2kDeZ8YfaHyZJ2U6Um9SEKqoDCSmxJ CgqPuZs8XI/lsT895Ae38JzORbrw5BkWybeFKF7d7Bk5yL2uVPOnOm2T3Ih+NBEPubYD OslA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature:arc-authentication-results; bh=K8tJIsZDnwwISK2il+zDImo2torBdzAG5Pn1ud4CRAo=; b=Xp/tKoew6+0msEgxdau1ttTrWEbyd3BCL4DvkgEXeOUuyk/mwrT1ZpBroJmqJZ5bCN FXksbIdroVjoYXajE/C73dczenaiG7r1VHvVAfoDO2vNcvxwKjyxUat4Ipjub6bbi3/k Rw+qpDvQBrPoJ2p7Rv4/C1TWJO6je6OrsNZS3oFdd2zg8G1HgXKcF0/8o3x7AuVlCMP1 AwMzUqv+fuMMOOXbpSlY/dEblnA9tjlNuQ7qNGpT9nnGQSs2B8JZZZQh5/AGxMIGx/mS +sw6eV/Tmd4pu8FLbO3JHYbjL30ZWjQODsYBr7fCTs/+pI4oDYbem9XhqiStakWIV9UN U+lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=f2R7NdvS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2-v6si6145817pfi.351.2018.08.23.16.01.22; Thu, 23 Aug 2018 16:01:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=f2R7NdvS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728379AbeHXCbx (ORCPT + 99 others); Thu, 23 Aug 2018 22:31:53 -0400 Received: from mail-qt0-f201.google.com ([209.85.216.201]:44496 "EHLO mail-qt0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727817AbeHXCbw (ORCPT ); Thu, 23 Aug 2018 22:31:52 -0400 Received: by mail-qt0-f201.google.com with SMTP id o18-v6so6119847qtm.11 for ; Thu, 23 Aug 2018 16:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=K8tJIsZDnwwISK2il+zDImo2torBdzAG5Pn1ud4CRAo=; b=f2R7NdvSXWugl/6TUcMP87qqCdGsRpOsCSW/sCRYTco818hjqpn8AFp9hOJ2w3DN9u GJ+zZyNjwvtU0OvBS7j/hKnnQGZ7V/Rp22vHVbRh3jp7xMzSZg6rPQjY4wvjubWUnbLN E8uMGOY6LV6FBfAB5Xaas8UQVmghqPd8DIevgB/w36vLnhCbcbmw3If8HinDSxE0t8eo 0UEZL7wq136JGTPVTRIxl85Yq8KQ074iIeXULSnwUL0IX49oaC2/dzg1H/ilr7UgQrgh cx2+FkSy4uJt0LKmnmCZSXm1eMZ0QWR2OH5sH5XiGKE0a3ZFn3ZdE6QbUWy9opN3iv9f V8yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=K8tJIsZDnwwISK2il+zDImo2torBdzAG5Pn1ud4CRAo=; b=NedUbc7kUW8afN3Qn2/GBTj/HVc0xTw7Z060u9TfN4dgCLnkWT3taM5AWk8qemf3Lz jXg8eDPeFQUqoGpUn0R/2oBiBGSBoAE37U8ZlanpU8y5/PEML/kXwEbHyIw5oR3sRD7j 1+Apsl31Gx1/TUgHrLdU0CHoBHiLl62ICHW6a8BUC0hl79KqOUpiUZhlv12z1KvsVAb9 Qa1zvwqKG77/SiuIp/nt/d2BzYbQLr3k9hFSAKLL6GMufn4b7kU815Rqn2t7Dp0DGcG+ VwM35qO8guB3XPhtcCdW7YJoutLgjyc/F0jussH1UfGY4JF/DGuheOrHVfK0pWomSdli ExmQ== X-Gm-Message-State: AOUpUlHPnO7wv4xZgpvSyzdLQnthxCRotNb6qi2RE8l8pH141yW+1FsU 5eP2Spx21D1Tmnsfb7IaXk/02ck4Ow== X-Received: by 2002:ac8:29fd:: with SMTP id 58-v6mr33566240qtt.6.1535065200797; Thu, 23 Aug 2018 16:00:00 -0700 (PDT) Date: Thu, 23 Aug 2018 15:59:35 -0700 Message-Id: <20180823225935.27035-1-yabinc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog Subject: [PATCH] perf: Force USER_DS when recording user stack data. From: Yabin Cui To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim Cc: linux-kernel@vger.kernel.org, Yabin Cui Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Perf can record user stack data in response to a synchronous request, such as a tracepoint firing. If this happens under set_fs(KERNEL_DS), then we end up reading user stack data using __copy_from_user_inatomic() under set_fs(KERNEL_DS). I think this conflicts with the intention of using set_fs(KERNEL_DS). And it is explicitly forbidden by hardware on ARM64 when both CONFIG_ARM64_UAO and CONFIG_ARM64_PAN are used. So fix this by forcing USER_DS when recording user stack data. Signed-off-by: Yabin Cui --- kernel/events/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 2a62b96600ad..9bc047421e75 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5948,6 +5948,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size, unsigned long sp; unsigned int rem; u64 dyn_size; + mm_segment_t fs; /* * We dump: @@ -5965,7 +5966,10 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size, /* Data. */ sp = perf_user_stack_pointer(regs); + fs = get_fs(); + set_fs(USER_DS); rem = __output_copy_user(handle, (void *) sp, dump_size); + set_fs(fs); dyn_size = dump_size - rem; perf_output_skip(handle, rem); -- 2.19.0.rc0.228.g281dcd1b4d0-goog