Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4456339ioa; Wed, 27 Apr 2022 04:24:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrFvAHOZ767hOckQsfLGe4TZl9jUp5vuD/tmPCHqCJHS/QgaS+kBl9P8ESB5DMxE6FVpot X-Received: by 2002:a05:6a00:140e:b0:4e1:c81a:625c with SMTP id l14-20020a056a00140e00b004e1c81a625cmr29443984pfu.39.1651058647749; Wed, 27 Apr 2022 04:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651058647; cv=none; d=google.com; s=arc-20160816; b=dd/AlSyrF5DaFNiONC9SRHMnUyXOOYZTbj/z/5bAEB99Mk60o2CmP9AF6wgbYFNeib Oownngz4eORD2mrOn9rGKdleg9i6sWPLVAClkAC7T1h1k5GfuL118MK1mKVeScxshTcZ k7mGYv0Q/xAS9Kt/6E5QUg0hGSTypeAdlvDh26F50ZOu676ppR/YNXEmVTxGEyxYsQBs pEUnLKiFZAZZmj6+MtzX5cQSpkIBQhbkU0hxw5mIb3EOFspkjxt1HaS9AYKiBugBADO7 o/W2wP2sLxwei6btg2BlkEoAMLRTkEuQ27Ut3E8pGp6om7Kyb8JZGgt85JEDohbqezkh sdDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=n1CPd29HHKe3iLELt5x5zSxX1l0GlMUVKgGqbXsXPsc=; b=a7afNLWzCVkHvF41FaXNsS3vio++l18lJZgckpCkiBxrFH1PfwEgmGUQ0z6T4DrVQy 2hV9Urh6ntnrBpDnLjkN35MlSqccHA441yXdGoxtzH3R2PsOomZoEk7bAzfV21Z4lIDO APk4xY/pb7+ilz94gRloPAWYFIOEHAC2Hj0yDB39DZbO0rIi4ZGcNoiYlWtL3KFhgGRb oZYoSTKL4sG5rmAGpMLvaVh0R2JkOKiFfAN0bCrSMXJyq9uutqwtbu4VP3pKylRFqSbL L1ZZZVOkr98uZftu+iKcyzIU4e+UWrccF5bPsgREernsX4k7dRjR+A52SyJ+/Z9zDMFd rHEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ul2x8GzR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h185-20020a6383c2000000b0039db5256a84si1183627pge.100.2022.04.27.04.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:24:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ul2x8GzR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 32A4342FF24; Wed, 27 Apr 2022 03:18:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353142AbiDZQrz (ORCPT + 99 others); Tue, 26 Apr 2022 12:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353139AbiDZQrs (ORCPT ); Tue, 26 Apr 2022 12:47:48 -0400 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30BE194B0E for ; Tue, 26 Apr 2022 09:44:34 -0700 (PDT) Received: by mail-ed1-x54a.google.com with SMTP id eg38-20020a05640228a600b00425d61d0302so4457200edb.17 for ; Tue, 26 Apr 2022 09:44:34 -0700 (PDT) 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=n1CPd29HHKe3iLELt5x5zSxX1l0GlMUVKgGqbXsXPsc=; b=Ul2x8GzRzl3HHeVNodduisFS+GirD7ttp4YhxIfHtZ/wAm96wAOKW0A3UvjvpnRyGE dGIlLM7rLl8SOQncEfIhzWSYbpzWK4FIquce/uniGQa5s5Khmoip2xUEMKpML79SS2Nr fjFDfjY+DOzRzBepJfAOlaHW98Dbj79IrR8+XSS3SP0heVjAw3rhmHavoXW9MHBQKoZG wag5mhU0cWEiD2fbJEejotrtfue9XD44tRsrIfEYSpEORbTnfzF4DdsV8zcndXNrqw8l /BmYauMIADOumK6gR7O9BDkDjdwUZNDb4ZrqS03yp+ROELB3q+NAfod4pzAvjwcIAOW/ JTFg== 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=n1CPd29HHKe3iLELt5x5zSxX1l0GlMUVKgGqbXsXPsc=; b=eiqS5UwvYza7zPJ2ZwGJxiTu81Pkib8v0a9KB9fAeeoCXMWhHeSt/TNkTlx961KG+2 EINNGEuCmbEUxM5Zu4bkmHHKUcHVJAPb45bX71rBroMUjEjqEFAiI4gwfSt6fYa4X6E0 Wcl+9I+yEVo1Yfucyatui5znjvwuoyj8f9fl4O2GrvaEpPQ7tN+BRGSdxIhA7ZC3lbGs xX6hRn17tGKWlJCDpEteWWoUMLHxscbejlxrXH1GasQb5lq1Da0oc6IRBQBadGE/c+dR KLz41AfKuaOPVIYzbRj6pCv+DmN5bs5PgUoJp8uByuCW5hpI9YYeiuNbBSC+9i+CfQuV nw9w== X-Gm-Message-State: AOAM531RQ+keJ0YSak5u1TLwfzpK3oJHrewLmxvSDEipvIHfNtE2mpZx pOUYd2fE3BLp5FtST9miu3iJVPk2UXE= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:d580:abeb:bf6d:5726]) (user=glider job=sendgmr) by 2002:a05:6402:1385:b0:413:2bc6:4400 with SMTP id b5-20020a056402138500b004132bc64400mr25986634edv.94.1650991473255; Tue, 26 Apr 2022 09:44:33 -0700 (PDT) Date: Tue, 26 Apr 2022 18:42:34 +0200 In-Reply-To: <20220426164315.625149-1-glider@google.com> Message-Id: <20220426164315.625149-6-glider@google.com> Mime-Version: 1.0 References: <20220426164315.625149-1-glider@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 05/46] x86: asm: instrument usercopy in get_user() and __put_user_size() From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use hooks from instrumented.h to notify bug detection tools about usercopy events in get_user() and put_user_size(). It's still unclear how to instrument put_user(), which assumes that instrumentation code doesn't clobber RAX. Signed-off-by: Alexander Potapenko --- Link: https://linux-review.googlesource.com/id/Ia9f12bfe5832623250e20f1859fdf5cc485a2fce --- arch/x86/include/asm/uaccess.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index f78e2b3501a19..0373d52a0543e 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -5,6 +5,7 @@ * User space memory access functions */ #include +#include #include #include #include @@ -99,11 +100,13 @@ extern int __get_user_bad(void); int __ret_gu; \ register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \ __chk_user_ptr(ptr); \ + instrument_copy_from_user_before((void *)&(x), ptr, sizeof(*(ptr))); \ asm volatile("call __" #fn "_%P4" \ : "=a" (__ret_gu), "=r" (__val_gu), \ ASM_CALL_CONSTRAINT \ : "0" (ptr), "i" (sizeof(*(ptr)))); \ (x) = (__force __typeof__(*(ptr))) __val_gu; \ + instrument_copy_from_user_after((void *)&(x), ptr, sizeof(*(ptr)), 0); \ __builtin_expect(__ret_gu, 0); \ }) @@ -248,7 +251,9 @@ extern void __put_user_nocheck_8(void); #define __put_user_size(x, ptr, size, label) \ do { \ + __typeof__(*(ptr)) __pus_val = x; \ __chk_user_ptr(ptr); \ + instrument_copy_to_user(ptr, &(__pus_val), size); \ switch (size) { \ case 1: \ __put_user_goto(x, ptr, "b", "iq", label); \ @@ -286,6 +291,7 @@ do { \ #define __get_user_size(x, ptr, size, label) \ do { \ __chk_user_ptr(ptr); \ + instrument_copy_from_user_before((void *)&(x), ptr, size); \ switch (size) { \ case 1: { \ unsigned char x_u8__; \ @@ -305,6 +311,7 @@ do { \ default: \ (x) = __get_user_bad(); \ } \ + instrument_copy_from_user_after((void *)&(x), ptr, size, 0); \ } while (0) #define __get_user_asm(x, addr, itype, ltype, label) \ -- 2.36.0.rc2.479.g8af0fa9b8e-goog