From patchwork Mon Jun 24 14:33:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11013409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F905186E for ; Mon, 24 Jun 2019 14:34:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 461FB28BF3 for ; Mon, 24 Jun 2019 14:34:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39A9928BFD; Mon, 24 Jun 2019 14:34:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7015A28BF9 for ; Mon, 24 Jun 2019 14:34:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FBBE8E0016; Mon, 24 Jun 2019 10:33:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5AE758E0002; Mon, 24 Jun 2019 10:33:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4762E8E0016; Mon, 24 Jun 2019 10:33:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 243B88E0002 for ; Mon, 24 Jun 2019 10:33:55 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id p34so17262487qtp.1 for ; Mon, 24 Jun 2019 07:33:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=N5aQVQiWWtXi9gCv0ztW+dfvhd60giz7b6IoZ6u0OIQ=; b=aUu6NulQ/9r5cIKfLGQhcEFsc6E/3IjZex3EZWl0KPHd15prBRN5DFxSYpbF/kTrXo ohfh0FfDVzpw8mEmrQUR6Uh1O36WCxdcPeeO1Qs1V+M13p8cNUMrqegQRVODS90W6T/U Vkr0HJv/RDePqKf3VPmXF8TNynB2LtK70mc1MeaOX2CFtCWkl3EaPOktdihe+3HJv0Ng 1EcOtdkRLIzT98SM3y6Gh6+Dos1lo9WDmyjCBTB2ORnYGqzehE3lZBoNDPXWjl7mnZHY edbdLx5bl92br7E4bGvv42Ptk+Z260xPZjxHyDfA1yF+s50p5qvRiqxPxPIkQw4x/C7L wMmA== X-Gm-Message-State: APjAAAX8+QybaH0SjnQ02FAN5WfVreD2s8QgAKTUws7B9wMudeTxDt/V CSrho6/6XZkuPSfIKfk4ofEfP3Ohwd6b5M0KVZTSjqN9zT0UWXDfpO0PIcp3aIoZkeatj3LgX3N i3Mqa/7CPme1WNqNHT5w29xXXYekBDP1t39Yw8jKllJsDe3K7ga1UZazOcY9hPaAK5Q== X-Received: by 2002:a0c:c782:: with SMTP id k2mr58478068qvj.53.1561386834897; Mon, 24 Jun 2019 07:33:54 -0700 (PDT) X-Received: by 2002:a0c:c782:: with SMTP id k2mr58477989qvj.53.1561386834209; Mon, 24 Jun 2019 07:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561386834; cv=none; d=google.com; s=arc-20160816; b=nDdzwdt5xhNSWH0F9VjJQAtxoBeiXd4DD4WXPBg0b2u97rFc9IRNNR9y8tDfH547t+ wGOt2k0I83CE3FmXEvgIlh0jqmP7OcItfBjrlbyKcbi/DuRejsxSf9IpTUQqsnYlIeww RYXnHykHDW6m8FWgpgkhhS1jakegcss+O5jx93Oq38HKgOhb1fpTKTX8ui9BZuJq737A shwiPTNiCaTro9sDqaEadtxXIhPIZngl+i9itxe1e0CoGArR31ux76IC1RE8WSK1gmGc e/EEoef7Rk2nuYspdCxswKIpsDep0XBPfJi/md08JU3T7E7L8wqJUBuZRRUs7hy2WnBg l8qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=N5aQVQiWWtXi9gCv0ztW+dfvhd60giz7b6IoZ6u0OIQ=; b=wdpoT9w1Enho9GdWDx7TKHduO81ytvEIfRam+M4yBE/JYfNdqXfI10dwAZk9sAthF1 J5cJNqibv99d2nNA0NJWxL4s/JWRQ1CR9EBglCdcV7tUg+i9eSpaMwQeXywXDs3eLAGk xvMz7tW4NuJdXFC0iXwBOJPzHCsOKi8eGm/WP72KlDV6+nl6KJdlFqIjg65ErwqOqW9D vhnTnLwW6PjpSE1UYRvZYC69kj0eBT+PyiaDL5bpbGG8Llu35CwKM0FxpzsMpROsADv/ Wuf6XCT+OEcNd+tFonrKyGL5ehQytgFJBawMD0kE7s+nrbZFIMsS8YhyO6dYk09Wr7HP E5gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qjhPznbY; spf=pass (google.com: domain of 3ud8qxqokceierhvi2orzpksskpi.gsqpmry1-qqozego.svk@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3Ud8QXQoKCEIerhvi2orzpksskpi.gsqpmry1-qqozego.svk@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id l63sor6525807qke.134.2019.06.24.07.33.54 for (Google Transport Security); Mon, 24 Jun 2019 07:33:54 -0700 (PDT) Received-SPF: pass (google.com: domain of 3ud8qxqokceierhvi2orzpksskpi.gsqpmry1-qqozego.svk@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qjhPznbY; spf=pass (google.com: domain of 3ud8qxqokceierhvi2orzpksskpi.gsqpmry1-qqozego.svk@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3Ud8QXQoKCEIerhvi2orzpksskpi.gsqpmry1-qqozego.svk@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=N5aQVQiWWtXi9gCv0ztW+dfvhd60giz7b6IoZ6u0OIQ=; b=qjhPznbYLqEoUuOd+SbruTmLg2XmfpstnWtNL0BmQkS/9+yQT+WCgWslxOFvIMH1pv mALN6TNaetS33pt/RVz6EBDIEWN2quqA6jv67UFd7koLos1e133OMWu359ZPg0J6bPcr 0XWlGuBxH86U+t+14QRd+rvD4clAF7jsa1nnvo0JS1ZiAdQXZxeWkV8d/rYp0KzGCh88 IiYVBvmMbwt07ocU9yE6vY4JutitBKtGPSxtSdK50DrOSaBmfZV7Ob9XJeo2Bom5V336 MrXYPuP6NQaYbAzK3Of68rTmuGoOGsh3GrYLnYHFg0fALTXz/unOR+Jpt7LYdYsFe3Zd cEhg== X-Google-Smtp-Source: APXvYqyNi91IprVlCjHeOaEl/XhVal8I6zy0NHm57SSOUiamYjJ/eflME47kK7EATSbEXYL1nBd99divk4S0n0PC X-Received: by 2002:ae9:e8ce:: with SMTP id a197mr16822243qkg.484.1561386833898; Mon, 24 Jun 2019 07:33:53 -0700 (PDT) Date: Mon, 24 Jun 2019 16:33:00 +0200 In-Reply-To: Message-Id: <0999c80cd639b78ae27c0674069d552833227564.1561386715.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH v18 15/15] selftests, arm64: add a selftest for passing tagged pointers to kernel From: Andrey Konovalov To: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Catalin Marinas , Vincenzo Frascino , Will Deacon , Mark Rutland , Andrew Morton , Greg Kroah-Hartman , Kees Cook , Yishai Hadas , Felix Kuehling , Alexander Deucher , Christian Koenig , Mauro Carvalho Chehab , Jens Wiklander , Alex Williamson , Leon Romanovsky , Luc Van Oostenryck , Dave Martin , Khalid Aziz , enh , Jason Gunthorpe , Christoph Hellwig , Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Robin Murphy , Kevin Brodsky , Szabolcs Nagy , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. This patch adds a simple test, that calls the uname syscall with a tagged user pointer as an argument. Without the kernel accepting tagged user pointers the test fails with EFAULT. Signed-off-by: Andrey Konovalov Acked-by: Kees Cook Reviewed-by: Catalin Marinas --- tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 +++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 ++++++++ tools/testing/selftests/arm64/tags_test.c | 29 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c diff --git a/tools/testing/selftests/arm64/.gitignore b/tools/testing/selftests/arm64/.gitignore new file mode 100644 index 000000000000..e8fae8d61ed6 --- /dev/null +++ b/tools/testing/selftests/arm64/.gitignore @@ -0,0 +1 @@ +tags_test diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile new file mode 100644 index 000000000000..a61b2e743e99 --- /dev/null +++ b/tools/testing/selftests/arm64/Makefile @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 + +# ARCH can be overridden by the user for cross compiling +ARCH ?= $(shell uname -m 2>/dev/null || echo not) + +ifneq (,$(filter $(ARCH),aarch64 arm64)) +TEST_GEN_PROGS := tags_test +TEST_PROGS := run_tags_test.sh +endif + +include ../lib.mk diff --git a/tools/testing/selftests/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/run_tags_test.sh new file mode 100755 index 000000000000..745f11379930 --- /dev/null +++ b/tools/testing/selftests/arm64/run_tags_test.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +echo "--------------------" +echo "running tags test" +echo "--------------------" +./tags_test +if [ $? -ne 0 ]; then + echo "[FAIL]" +else + echo "[PASS]" +fi diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags_test.c new file mode 100644 index 000000000000..22a1b266e373 --- /dev/null +++ b/tools/testing/selftests/arm64/tags_test.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +#define SHIFT_TAG(tag) ((uint64_t)(tag) << 56) +#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \ + SHIFT_TAG(tag)) + +int main(void) +{ + static int tbi_enabled = 0; + struct utsname *ptr, *tagged_ptr; + int err; + + if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0) + tbi_enabled = 1; + ptr = (struct utsname *)malloc(sizeof(*ptr)); + if (tbi_enabled) + tagged_ptr = (struct utsname *)SET_TAG(ptr, 0x42); + err = uname(tagged_ptr); + free(ptr); + + return err; +}