From patchwork Thu Dec 9 22:15:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12695541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 03CE1C433F5 for ; Thu, 9 Dec 2021 22:21:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=fjY3xoWeEErXxsCyOc8dbuD1oZXpkYjPf0jJyBRuu8Q=; b=Eu1c7S1Sv/0nN5bypK4j1Wr++4 IAn4IpdwcH0Qsumclw0rM048WqCywtzG7aiu6btwGspLRsGYGay3YvOrKtl6B8Ks0eAWjTMFHTiIF WSm/Ql4Gc51nINiwl16OdZzoBz5sfvWPoXQArsKx7pkRup14cgjz5VWmuKysCwVswdU2/ivLqPku0 aevlcJv15AKU1S5UykLnUtLXnMZesUbWySkv0mu3liWxilwcWJB+xfpstwRKkm6LD//2PsfKN460/ aM6WzRSpnXEGDoV2QyomaohFQOgRhGjlK6/RIJaMXtSGd5whhTu05tSKXiIsbABEQ7Tq1mlhHFBQo Zx+qMvkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvRkS-000DHe-Sg; Thu, 09 Dec 2021 22:18:47 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvRhr-000CFQ-9x for linux-arm-kernel@lists.infradead.org; Thu, 09 Dec 2021 22:16:05 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s189-20020a252cc6000000b005c1f206d91eso12985009ybs.14 for ; Thu, 09 Dec 2021 14:16:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=FqrxnquBZTtko9BgXrPYz8OM9HQeZt54ZJSaNv8spPQ=; b=jQlgqpqABmoSDMhC0f6Qnl7fD27iyQFDbN5T3LT3Lqxa6lEVdKbUcNYfBhPXkY45rU BXcZKwud2NUlWZ3kU1dYlexeBjY51JW4XuxO2VAWGDwDv8LZfKHrHvAwxW6I77JxMoek TpP2g0OWY8LDi4kr05Sj8id/av85FV+Dd2QpNlGmPpBI5o6HrF9GPUlPWjrW8crWSEVq 8vK3/T7G/GLj0fOEsDL11ZAldUawwtlrUjC3Rb9PrFBlAXnxQCRK9aLzK8TQQTMI/EJq Ih86fCRJuVBphQCEWO4vHu+S/JhBEHf8M9Nd1VnQrbXIInApfvisvBMyZE+kCod1MAqJ AnKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=FqrxnquBZTtko9BgXrPYz8OM9HQeZt54ZJSaNv8spPQ=; b=Z/4EybrTh7gwCeCZnTFQHQ6JQF0OwMXC30tqi523BLzXGhmzy8zhOIAaTWQDqkgKF5 +wR4wbDmsn9VT+BP8ZI0oRmVlM25/xdvcPbVH4cLloNDsl4qtRUOqhsHx2OXOcRFxrEN obxIH3GkXoYTm5djJryc+zm/oBgIB9VkF3AlmFwGFYdWPktcGuopvRk5ahsn3flq4gZz jjTH5p++sAb5bMcQjjsra3jbAf98xk4JY1gphA7xPDVb6EHJ1FJwp3EMTmVPukcs3d+6 /uV4OYINdeOqEwfNqyo/2v5U0AHIfvDZiMBSOqbG0gVyvRZ/78dAZ55wHeQZ8SndHO+6 lLAw== X-Gm-Message-State: AOAM532qgGld9x9xWdP634jxUcsUOq2WIWEdoY6hSNJVO+jzBLF/YU7f bZ8Y6TZh26aJ5SYKLuSaur1g1og= X-Google-Smtp-Source: ABdhPJz7A/DINf05BcsrLAG8T6qlShSq6crx7l0ZreU7rhk+PSIj2ScgiWw65k8/EeZ03uva6ksbsbA= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:f233:e324:8aa0:f65c]) (user=pcc job=sendgmr) by 2002:a25:69c1:: with SMTP id e184mr9817470ybc.235.1639088161742; Thu, 09 Dec 2021 14:16:01 -0800 (PST) Date: Thu, 9 Dec 2021 14:15:41 -0800 In-Reply-To: <20211209221545.2333249-1-pcc@google.com> Message-Id: <20211209221545.2333249-5-pcc@google.com> Mime-Version: 1.0 References: <20211209221545.2333249-1-pcc@google.com> X-Mailer: git-send-email 2.34.1.173.g76aa8bc2d0-goog Subject: [PATCH v4 4/7] uaccess-buffer: add CONFIG_GENERIC_ENTRY support From: Peter Collingbourne To: Catalin Marinas , Will Deacon , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Thomas Gleixner , Andy Lutomirski , Kees Cook , Andrew Morton , Masahiro Yamada , Sami Tolvanen , YiFei Zhu , Mark Rutland , Frederic Weisbecker , Viresh Kumar , Andrey Konovalov , Peter Collingbourne , Gabriel Krisman Bertazi , Chris Hyser , Daniel Vetter , Chris Wilson , Arnd Bergmann , Dmitry Vyukov , Christian Brauner , "Eric W. Biederman" , Alexey Gladkov , Ran Xiaokai , David Hildenbrand , Xiaofeng Cao , Cyrill Gorcunov , Thomas Cedeno , Marco Elver , Alexander Potapenko Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Evgenii Stepanov X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211209_141603_499294_C3D13CD7 X-CRM114-Status: GOOD ( 17.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add uaccess logging support on architectures that use CONFIG_GENERIC_ENTRY (currently only s390 and x86). Link: https://linux-review.googlesource.com/id/I3c5eb19a7e4a1dbe6095f6971f7826c4b0663f7d Signed-off-by: Peter Collingbourne Acked-by: Dmitry Vyukov --- v4: - move pre/post-exit-loop calls into if statement arch/Kconfig | 1 + include/linux/entry-common.h | 2 ++ include/linux/thread_info.h | 4 ++++ kernel/entry/common.c | 14 +++++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index 17819f53ea80..bc849a61b636 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -31,6 +31,7 @@ config HOTPLUG_SMT bool config GENERIC_ENTRY + select HAVE_ARCH_UACCESS_BUFFER bool config KPROBES diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h index 2e2b8d6140ed..973fcd1d48a3 100644 --- a/include/linux/entry-common.h +++ b/include/linux/entry-common.h @@ -42,12 +42,14 @@ SYSCALL_WORK_SYSCALL_EMU | \ SYSCALL_WORK_SYSCALL_AUDIT | \ SYSCALL_WORK_SYSCALL_USER_DISPATCH | \ + SYSCALL_WORK_UACCESS_BUFFER_ENTRY | \ ARCH_SYSCALL_WORK_ENTER) #define SYSCALL_WORK_EXIT (SYSCALL_WORK_SYSCALL_TRACEPOINT | \ SYSCALL_WORK_SYSCALL_TRACE | \ SYSCALL_WORK_SYSCALL_AUDIT | \ SYSCALL_WORK_SYSCALL_USER_DISPATCH | \ SYSCALL_WORK_SYSCALL_EXIT_TRAP | \ + SYSCALL_WORK_UACCESS_BUFFER_EXIT | \ ARCH_SYSCALL_WORK_EXIT) /* diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index ad0c4e041030..b0f8ea86967f 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -46,6 +46,8 @@ enum syscall_work_bit { SYSCALL_WORK_BIT_SYSCALL_AUDIT, SYSCALL_WORK_BIT_SYSCALL_USER_DISPATCH, SYSCALL_WORK_BIT_SYSCALL_EXIT_TRAP, + SYSCALL_WORK_BIT_UACCESS_BUFFER_ENTRY, + SYSCALL_WORK_BIT_UACCESS_BUFFER_EXIT, }; #define SYSCALL_WORK_SECCOMP BIT(SYSCALL_WORK_BIT_SECCOMP) @@ -55,6 +57,8 @@ enum syscall_work_bit { #define SYSCALL_WORK_SYSCALL_AUDIT BIT(SYSCALL_WORK_BIT_SYSCALL_AUDIT) #define SYSCALL_WORK_SYSCALL_USER_DISPATCH BIT(SYSCALL_WORK_BIT_SYSCALL_USER_DISPATCH) #define SYSCALL_WORK_SYSCALL_EXIT_TRAP BIT(SYSCALL_WORK_BIT_SYSCALL_EXIT_TRAP) +#define SYSCALL_WORK_UACCESS_BUFFER_ENTRY BIT(SYSCALL_WORK_BIT_UACCESS_BUFFER_ENTRY) +#define SYSCALL_WORK_UACCESS_BUFFER_EXIT BIT(SYSCALL_WORK_BIT_UACCESS_BUFFER_EXIT) #endif #include diff --git a/kernel/entry/common.c b/kernel/entry/common.c index d5a61d565ad5..59ec6e3f793b 100644 --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "common.h" @@ -70,6 +71,9 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall, return ret; } + if (work & SYSCALL_WORK_UACCESS_BUFFER_ENTRY) + uaccess_buffer_syscall_entry(); + /* Either of the above might have changed the syscall number */ syscall = syscall_get_nr(current, regs); @@ -197,14 +201,19 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs, static void exit_to_user_mode_prepare(struct pt_regs *regs) { unsigned long ti_work = READ_ONCE(current_thread_info()->flags); + bool uaccess_buffer_pending; lockdep_assert_irqs_disabled(); /* Flush pending rcuog wakeup before the last need_resched() check */ tick_nohz_user_enter_prepare(); - if (unlikely(ti_work & EXIT_TO_USER_MODE_WORK)) + if (unlikely(ti_work & EXIT_TO_USER_MODE_WORK)) { + bool uaccess_buffer_pending = uaccess_buffer_pre_exit_loop(); + ti_work = exit_to_user_mode_loop(regs, ti_work); + uaccess_buffer_post_exit_loop(uaccess_buffer_pending); + } arch_exit_to_user_mode_prepare(regs, ti_work); @@ -247,6 +256,9 @@ static void syscall_exit_work(struct pt_regs *regs, unsigned long work) audit_syscall_exit(regs); + if (work & SYSCALL_WORK_UACCESS_BUFFER_EXIT) + uaccess_buffer_syscall_exit(); + if (work & SYSCALL_WORK_SYSCALL_TRACEPOINT) trace_sys_exit(regs, syscall_get_return_value(current, regs));