From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3929CC28CC5 for ; Sat, 8 Jun 2019 03:56:34 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D7C02089E for ; Sat, 8 Jun 2019 03:56:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EkMES4+w"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="dA3axcy3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D7C02089E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OHD0koyls46FJOWp6HPPYJ4SwCBgtrGq3wJ3kYqDi9I=; b=EkMES4+wbOqfpk yhwEarqXsZCiokqNMRO1vDLMG8FiFFJqJDesh8WZUJUiwXJpSU9w2lTIifRKXGCQRSwkZbQuYdXWH 6WqQAOVV/PDgL9Em5ouOaOlHSVizb4DFu/eh5c+mEaVm/VURDbFL1lNMBHkVmKkiftRvtDMFKlAp1 ahBVnj5tm9lyN8v8eGReG3j+HI/lIaiT+EyKmN+yLNDpWBynAhY6NLA0xfeJM8cdYK/WYlj12uxju SbD64P78id3Mx24NS0XP53TibBce5HiSLBt1guxE8tzjLd5XeSn3i11u3CntpnI8+XhCNs7aJdfmc RDtaIEPS9v8eACs023Ng==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hZST0-0002yx-5E; Sat, 08 Jun 2019 03:56:30 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hZSSw-0002yO-Mi for linux-arm-kernel@lists.infradead.org; Sat, 08 Jun 2019 03:56:28 +0000 Received: by mail-pl1-x642.google.com with SMTP id bi6so1137431plb.12 for ; Fri, 07 Jun 2019 20:56:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Sg8hZnfRQyshVayh9AfBUaCUwYP0fG+PoifVRoQ1/2U=; b=dA3axcy3OSjQBllR3jO2rSL28yV4HEUJp/aPnDeszFXA+QJykqsQIUJ72CJFJfYEfw wdg907Km6KiqXC2789/OeRpcFlLBSZiEqKz1cQEJwy/XIHhLz8qR/HqqVrGp+0QeTjJc WftaB+rnktSZBXZ74MuozosAkMHfiOKMwo6jY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Sg8hZnfRQyshVayh9AfBUaCUwYP0fG+PoifVRoQ1/2U=; b=q8HkECxH8sjyFO+8mob3D0cmT2m+n9Db5CTrIYGSO2m+GC87pSkiZcC1Q0LQ8kZm9V f3cu+A8ud3R3E2pTjJRbgifDlvubP4s8uLTI6UAa09yoylP88clsQWyfBnEdrEc+bxqz Er74a3UZrbOsZV+/8b5Q5PtWditGIBA5GyNoNRuAZcWJwvZpbWH8+fP1RCylfb2MpDeJ qCv12W2l3PrbfFqsnbQoY1Qlo7le20wyBZ90sVgZfF9zO1/S525boCcoVE6A0rQsg4XW CGU84CPX5r2i9dkw3dBqWaRJPWyZlbjqhLgQ+hYE1aI+Qh3ZfsbjY49zc4e4KIfDSom9 3eUw== X-Gm-Message-State: APjAAAUOkKzY/QgjjLRiwoPfYzsK87ifbUPVHhJbNaO+cMgV+lvGmMYS mdpm2QUeaIg4/BHSHGC6iPaDYQ== X-Google-Smtp-Source: APXvYqxOa+LbIfSKzO98kP7ZimZglTjC5TFvL11aIkaQBz55ZFGw6dQUA6lPd2PVhnyZkGPHF3XY8g== X-Received: by 2002:a17:902:6948:: with SMTP id k8mr59073078plt.81.1559966186036; Fri, 07 Jun 2019 20:56:26 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c6sm6781898pfm.163.2019.06.07.20.56.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jun 2019 20:56:25 -0700 (PDT) Date: Fri, 7 Jun 2019 20:56:24 -0700 From: Kees Cook To: Andrey Konovalov Subject: Re: [PATCH v16 16/16] selftests, arm64: add a selftest for passing tagged pointers to kernel Message-ID: <201906072055.7DFED7B@keescook> References: <9e1b5998a28f82b16076fc85ab4f88af5381cf74.1559580831.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <9e1b5998a28f82b16076fc85ab4f88af5381cf74.1559580831.git.andreyknvl@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190607_205626_789426_8F8D6AD7 X-CRM114-Status: GOOD ( 21.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kvm@vger.kernel.org, Szabolcs Nagy , Catalin Marinas , Will Deacon , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Khalid Aziz , linux-kselftest@vger.kernel.org, Felix Kuehling , Vincenzo Frascino , Shuah Khan , Jacob Bramley , Leon Romanovsky , linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, Christoph Hellwig , Jason Gunthorpe , Dmitry Vyukov , Dave Martin , Evgeniy Stepanov , linux-media@vger.kernel.org, Kevin Brodsky , Ruben Ayrapetyan , Ramana Radhakrishnan , Alex Williamson , Mauro Carvalho Chehab , linux-arm-kernel@lists.infradead.org, Kostya Serebryany , Greg Kroah-Hartman , Yishai Hadas , linux-kernel@vger.kernel.org, Jens Wiklander , Lee Smith , Alexander Deucher , Andrew Morton , enh , Robin Murphy , Christian Koenig , Luc Van Oostenryck Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jun 03, 2019 at 06:55:18PM +0200, Andrey Konovalov wrote: > This patch is a part of a series that extends arm64 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 I'm adding Shuah to CC in case she has some suggestions about the new selftest. Reviewed-by: Kees Cook -Kees > --- > tools/testing/selftests/arm64/.gitignore | 1 + > tools/testing/selftests/arm64/Makefile | 22 ++++++++++ > .../testing/selftests/arm64/run_tags_test.sh | 12 ++++++ > tools/testing/selftests/arm64/tags_lib.c | 42 +++++++++++++++++++ > tools/testing/selftests/arm64/tags_test.c | 18 ++++++++ > 5 files changed, 95 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_lib.c > 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..9dee18727923 > --- /dev/null > +++ b/tools/testing/selftests/arm64/Makefile > @@ -0,0 +1,22 @@ > +# SPDX-License-Identifier: GPL-2.0 > + > +include ../lib.mk > + > +# 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_CUSTOM_PROGS := $(OUTPUT)/tags_test > + > +$(OUTPUT)/tags_test: tags_test.c $(OUTPUT)/tags_lib.so > + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $< > + > +$(OUTPUT)/tags_lib.so: tags_lib.c > + $(CC) -o $@ -shared $(CFLAGS) $(LDFLAGS) $^ > + > +TEST_PROGS := run_tags_test.sh > + > +all: $(TEST_CUSTOM_PROGS) > + > +endif > 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..2bbe0cd4220b > --- /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 "--------------------" > +LD_PRELOAD=./tags_lib.so ./tags_test > +if [ $? -ne 0 ]; then > + echo "[FAIL]" > +else > + echo "[PASS]" > +fi > diff --git a/tools/testing/selftests/arm64/tags_lib.c b/tools/testing/selftests/arm64/tags_lib.c > new file mode 100644 > index 000000000000..8a674509216e > --- /dev/null > +++ b/tools/testing/selftests/arm64/tags_lib.c > @@ -0,0 +1,42 @@ > +#include > + > +#define TAG_SHIFT (56) > +#define TAG_MASK (0xffUL << TAG_SHIFT) > + > +void *__libc_malloc(size_t size); > +void __libc_free(void *ptr); > +void *__libc_realloc(void *ptr, size_t size); > +void *__libc_calloc(size_t nmemb, size_t size); > + > +static void *tag_ptr(void *ptr) > +{ > + unsigned long tag = rand() & 0xff; > + if (!ptr) > + return ptr; > + return (void *)((unsigned long)ptr | (tag << TAG_SHIFT)); > +} > + > +static void *untag_ptr(void *ptr) > +{ > + return (void *)((unsigned long)ptr & ~TAG_MASK); > +} > + > +void *malloc(size_t size) > +{ > + return tag_ptr(__libc_malloc(size)); > +} > + > +void free(void *ptr) > +{ > + __libc_free(untag_ptr(ptr)); > +} > + > +void *realloc(void *ptr, size_t size) > +{ > + return tag_ptr(__libc_realloc(untag_ptr(ptr), size)); > +} > + > +void *calloc(size_t nmemb, size_t size) > +{ > + return tag_ptr(__libc_calloc(nmemb, size)); > +} > diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags_test.c > new file mode 100644 > index 000000000000..263b302874ed > --- /dev/null > +++ b/tools/testing/selftests/arm64/tags_test.c > @@ -0,0 +1,18 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include > +#include > +#include > +#include > +#include > + > +int main(void) > +{ > + struct utsname *ptr; > + int err; > + > + ptr = (struct utsname *)malloc(sizeof(*ptr)); > + err = uname(ptr); > + free(ptr); > + return err; > +} > -- > 2.22.0.rc1.311.g5d7573a151-goog > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel