From patchwork Mon Aug 6 16:40:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10557417 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 0344815A6 for ; Mon, 6 Aug 2018 16:41:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E510429919 for ; Mon, 6 Aug 2018 16:41:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D670929941; Mon, 6 Aug 2018 16:41:14 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 75625298D8 for ; Mon, 6 Aug 2018 16:41:14 +0000 (UTC) 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:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=J/ipLxylslD+4TvA1SMRZEs6U5A6+H3QWnBN3HFojNs=; b=G+dD91oHlU62Xe A1AWZBe/lhhS9lARvLiW0BpkbcnmU73usmMIkDfcPOipIX9FXwZCMxnxeyDy57x/GB/5gdyw3b5VE tbx/e+i4DjmgokoZ28AaMcIk+eTuPJoXfvHMX+BkMFtsSdu7nATM6R5bkO53rnsKa4riywkUTL7sj jZDQQI7qtrMALnwqy3N16ho8Sre7vpuz0oT/ys+bGq9smeUAcKaA8tujUoGGRmmWAN1A0yZynQ2xr pWhyr7HbxDUk9akY45eleX97TYLn/IjixmcjmS+H+O4i9iwW/Gi92Bw7bWBEfkxQ5o3ePaw1E1KHT frucoAN0BOGOuixJtwTA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmiZD-0007aw-4g; Mon, 06 Aug 2018 16:41:11 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmiZ9-0007TR-P8 for linux-arm-kernel@lists.infradead.org; Mon, 06 Aug 2018 16:41:09 +0000 Received: by mail-wr1-x443.google.com with SMTP id v14-v6so12996738wro.5 for ; Mon, 06 Aug 2018 09:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4JRXIJLBl4B77V9Zp1bHxiibsTuS9qYiG3W/7d2vbs4=; b=R/QQR8lwOQTXtE/oXjwJAsQ6MM1WVm3FlazsgX/aoQPMCA3dcLUASxhKx4Pplf+yQ0 4V6ug1JKt6ziqBRwZwS6iAO/g/BNVmuE7M2z4Nff3l5qA5wV1pMDNQLQ1p0gtpBorb9e NoeOSZTbjM0O1xmOde+LtERaVHKcYoHkCDQbmqESNjs2LQt8eekMRKU1W7qZSAW6qLVm +Fx6xH5Mcstxa2SY1Bw3MH4BsO/uZ4RxFoG8EwEACbqq2dLYGgzO73m28tBdYs5VGwY6 F9xMgGSLTnvUPRGcD/MP48ffV2V5nBKIZ6NP4Oah6+pSKfI1QsVECqebnw0Pac8qDleP BHSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4JRXIJLBl4B77V9Zp1bHxiibsTuS9qYiG3W/7d2vbs4=; b=BKNATQxoUtJiBgrjlRchHUIF0r7pOyoRKBd6Mw27x9GyXsfHd1hI6vV3OfJl8N8W5X 0zRfQLntug3ESpRH/ZPeViC38mSeZwrNHv7IR2wdwuQpfxLFo4ol5R5PINPO6pn5ZmR6 5XuvHGsLF/dM6k69ZgqNJVjzVjA4CInPb/XXoasACA0vs+FIxakHLsHcyvlDB3jkorZM T8I+yjajOGhBVErbadcNbY6W/MnYyp/KACkIPDdhioPDWZU0W/PY070aR3W1je67il4h 5dI0hWWEL335gJucXTO2s9YQ1kP4HHVJb9k2z4X+PIBc02dT/UjAolKR6UcxreZHKa/t XTHA== X-Gm-Message-State: AOUpUlEq7UYdurnNP5NZWVxTqnBhR2oOefBNDulE+qzl7WiX+XFis8io Q7oZUwudUgvLB4EYZQhwNQqLMw== X-Google-Smtp-Source: AAOMgpevV7lqMLifigVw6GPYsm4a3KGutEKLiEuzKRNJ7bqKjYjYA3wEC5YWatl/Eu1t3nonlXKnTg== X-Received: by 2002:a5d:504d:: with SMTP id h13-v6mr9764161wrt.18.1533573652777; Mon, 06 Aug 2018 09:40:52 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id 66-v6sm16385790wmw.34.2018.08.06.09.40.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 09:40:52 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Al Viro , Andrey Konovalov , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 00/10] arm64: untag user pointers passed to the kernel Date: Mon, 6 Aug 2018 18:40:35 +0200 Message-Id: X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180806_094107_820486_2FDAF5F0 X-CRM114-Status: GOOD ( 17.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chintan Pandya , Jacob Bramley , Ruben Ayrapetyan , Lee Smith , Kostya Serebryany , Dmitry Vyukov , Ramana Radhakrishnan , Evgeniy Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP arm64 has a feature called Top Byte Ignore, which allows to embed pointer tags into the top byte of each pointer. Userspace programs (such as HWASan, a memory debugging tool [1]) might use this feature and pass tagged user pointers to the kernel through syscalls or other interfaces. This patch makes a few of the kernel interfaces accept tagged user pointers. The kernel is already able to handle user faults with tagged pointers and has the untagged_addr macro, which this patchset reuses. Thanks! [1] http://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html Changes in v5: - Added 3 new patches that add untagging to places found with static analysis. - Rebased onto 44c929e1 (4.18-rc8). Changes in v4: - Added a selftest for checking that passing tagged pointers to the kernel succeeds. - Rebased onto 81e97f013 (4.18-rc1+). Changes in v3: - Rebased onto e5c51f30 (4.17-rc6+). - Added linux-arch@ to the list of recipients. Changes in v2: - Rebased onto 2d618bdf (4.17-rc3+). - Removed excessive untagging in gup.c. - Removed untagging pointers returned from __uaccess_mask_ptr. Changes in v1: - Rebased onto 4.17-rc1. Changes in RFC v2: - Added "#ifndef untagged_addr..." fallback in linux/uaccess.h instead of defining it for each arch individually. - Updated Documentation/arm64/tagged-pointers.txt. - Dropped "mm, arm64: untag user addresses in memory syscalls". - Rebased onto 3eb2ce82 (4.16-rc7). Andrey Konovalov (10): arm64: add type casts to untagged_addr macro uaccess: add untagged_addr definition for other arches arm64: untag user addresses in access_ok and __uaccess_mask_ptr mm, arm64: untag user addresses in mm/gup.c lib, arm64: untag addrs passed to strncpy_from_user and strnlen_user arm64: untag user address in __do_user_fault fs, arm64: untag user address in copy_mount_options usb, arm64: untag user addresses in devio arm64: update Documentation/arm64/tagged-pointers.txt selftests, arm64: add a selftest for passing tagged pointers to kernel Documentation/arm64/tagged-pointers.txt | 5 +++-- arch/arm64/include/asm/uaccess.h | 14 +++++++++----- arch/arm64/mm/fault.c | 2 +- drivers/usb/core/devio.c | 8 +++++--- fs/namespace.c | 2 +- include/linux/uaccess.h | 4 ++++ lib/strncpy_from_user.c | 2 ++ lib/strnlen_user.c | 2 ++ mm/gup.c | 4 ++++ 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 | 19 +++++++++++++++++++ 13 files changed, 74 insertions(+), 12 deletions(-) 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