Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7454655ybi; Mon, 8 Jul 2019 22:18:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSZfa/aXImExuRnvBXSwKpUtCrlp7FHQy6JLsDwBBW3fyNQzK9NrzylnfFYGMFaeJp+4JR X-Received: by 2002:a65:4808:: with SMTP id h8mr27976694pgs.22.1562649510681; Mon, 08 Jul 2019 22:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562649510; cv=none; d=google.com; s=arc-20160816; b=GqMI7OwrwBcamz6S+auN5WJSDwJTNSvmXe8YbxqiQTBDe9gdZ3/32XawDxcemTZ+Ym 4oh9Ra5RdmKX3lht2uUqPZwCINeCWAEFVunB3DfKlJLA+wX2AZTvTOG8e0dwgnsC6HVE 5avI6hZ3tz/DSIuHW4P5neRk5BMVv76gN8MA6Wvac8jJFgNP+GnIIOUTgMWfXFAnuMz4 KWrBX8VmcY8YZTibBiIhvU6YLQJmGweUgZYOwVaviOOerJ/JEe5QVeGIuMtpWlJ+FbiZ eEguQUzQJPeUq6nkTz5ocmyQDcyKpznlRUhao8dkHi8/qJexJyIPCRr1ulQoxnF4DhIE q2Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:references:cc:to:from:subject :dkim-signature; bh=1rAXHSkSARQHYnD/3+ONHPyJ9ZYNgeq0KpN+wQR1HeY=; b=ebHj2KLuwSh5vwKW72uMPNvB/1SJiVXZKhYNyj1bMwCes6Yke7vLCJlMIDgCL1C2Kb qHm+FraOPIUTLz0kGHlazkrzCeLRyJ2M5MZdgmGNvnMWYsoAd+4e0P7pyk/pfruDATAf GAuSE2ka+emCl9oQYZ5Z+CQ9Gx5shrZ8uDU+8wsRCk8/RDam68zjW+LUqUR2/CHI6Ojh sDmacqDiFE4CD4A5267bjk2aNBFOvl4q5X8QNXwFMRmc69tKLlDRH+5YsmguWCoELlYJ wID8CUUzcgSYW/vAS53y9jjrg8+GNb/MVQQTkTFTg6xxfCOLLdknmXAMYj7P3m6B785E Shhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@etsukata-com.20150623.gappssmtp.com header.s=20150623 header.b=Gsl57WJm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g22si22575308pfh.219.2019.07.08.22.18.14; Mon, 08 Jul 2019 22:18:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@etsukata-com.20150623.gappssmtp.com header.s=20150623 header.b=Gsl57WJm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726055AbfGIFRS (ORCPT + 99 others); Tue, 9 Jul 2019 01:17:18 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34503 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbfGIFRS (ORCPT ); Tue, 9 Jul 2019 01:17:18 -0400 Received: by mail-pl1-f194.google.com with SMTP id i2so9456566plt.1 for ; Mon, 08 Jul 2019 22:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsukata-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=1rAXHSkSARQHYnD/3+ONHPyJ9ZYNgeq0KpN+wQR1HeY=; b=Gsl57WJmxX/Zxo1E5g1fMGJ1b6GyuzxM3uqaQWkPEZ7lopslpgwKxCTdNJODx48V4H nd7BqIuYVNDMfvJL+XAntcSao3YnkZJo6n36sBNxx/c0aQVvjGrxLcwd2fFMM35EWxwV tEtg/TaqQ9F5yzHQfsuNEq1KC1KZ7PxRJeAcyVNL22p5SDJ9Y75o42VRxUaOXu7tB6Kp CSWbLVU6sniANl2jtT2ObGoJ5ulAo6OjtgE6heXRMukCRJqB0ZcoLBQaFiX9H5Gbx/DN xAHIQ+u4G2Vris8f9lkCbNoMLV750ltGl041U9m13Eue6QGksBMJAX5Fepjo54A0Gm5y 7pbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=1rAXHSkSARQHYnD/3+ONHPyJ9ZYNgeq0KpN+wQR1HeY=; b=S1c7AbGOl1vpGySLMR+6E2jV4somltRkkN7Wrt3Ry+ZAhAdhGbcUFj14oAzXCXB7Ac elwCnHoo2qcik/CC10LnSbKexF98Sv5K6x52kcCrv/uxpGHKrzDjJ6H+P3cY7AG+73Gq E2Q05tuufhWC9E9c/h3WkmxPcjgvYG/H9DJFXESTXp+F8E0CsGQhuB4azznnDVe2dpMU IMHxnQITIykRf4tXVa3xeT3ox5CAiCeEW/ktIfw3UTOwerB/UHOSC66UCN30p83kAQiZ UB7EnTrELk43i3lVeBWjvHA+9KnTl2tSfv7i7bGFeXt3ygouUq3zKddPNTRDhBaBJHio HBGw== X-Gm-Message-State: APjAAAV6H5GIJGYZKxAzEP72oYt/aVmm49kN7z4cL6RF95Ghs6NDuu5P UfnPL+yoNrOGe9zuCuoNV3Ye+g== X-Received: by 2002:a17:902:8d97:: with SMTP id v23mr28993443plo.157.1562649437489; Mon, 08 Jul 2019 22:17:17 -0700 (PDT) Received: from etsukata.local (fs76eecbcd.tkyc008.ap.nuro.jp. [118.238.203.205]) by smtp.gmail.com with ESMTPSA id e124sm28663013pfh.181.2019.07.08.22.17.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jul 2019 22:17:16 -0700 (PDT) Subject: Re: [PATCH v2 5/7] x86/mm, tracing: Fix CR2 corruption From: Eiichi Tsukata To: Peter Zijlstra Cc: Linus Torvalds , Thomas Gleixner , Borislav Petkov , Ingo Molnar , Steven Rostedt , Andrew Lutomirski , Peter Anvin , Dave Hansen , Juergen Gross , Linux List Kernel Mailing , He Zhe , Joel Fernandes References: <20190704195555.580363209@infradead.org> <20190704200050.534802824@infradead.org> <20190708074823.GV3402@hirez.programming.kicks-ass.net> <48e29640-fedc-3e72-535c-27ef07b73938@etsukata.com> Openpgp: preference=signencrypt Autocrypt: addr=devel@etsukata.com; keydata= mQINBFydxe0BEAC2IUPqvxwzh0TS8DvqmjU+pycCq4xToLnCTy9gfmHd/mJWGykQJ7SXXFg2 bTAp8XcITVEDvhMUc0G4l+RBYkArwkaMHO5iM4a7+Gnn6beV1CL/dk9Wu5gkThgL11bhyKmQ Ub1duuVkX3fN2cRW2DrHsTp+Bxd/pq5rrKAbA/LIFmF4Oipapgr69I5wUeYywpzPFuaVkoZc oLdAscwEvPImSOAAJN0sesBW9sBAH34P+xaW2/Mug5aNUm/K6whApeFV/qz2UuOGjzY4fbYw AjK1ALIK8rdeAPxvp2e1dXrj29YrIZ2DkzdR0Y9O8Lfz1Pp5aQ+pwUQzn2vWA3R45IItVtV5 8v04N/F7rc/1OHFpgFtzgAO2M51XiIPdbSmF/WuWPsdEHWgpVW3H/I8amstfH519Xb/AOKYQ 7a14/3EESVuqXyyfCdTVnBNRRY0qXJ7mA0oParMD8XKMOVLj6Nlvs2Zh2LjNJhUDsssKNBg+ sMKiaeSV8dtcbH2XCc2GDKsYbrIKG3cu5nZl8xjlM3WdtdvqWpuHj6KTYBQgsXngBA7TDZWT /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WjNe5s1rK9a/z/K3Bhk/ojDEJHSeXEr3siS2/6E4UhDNXd/ZGZi5fRI2lo8Cp+oTS0Q m6FIxqnoPWVCsi1XJdSSQtTMxU0qesAjRXTPE76lMdUQkYZ/Ux1rbzYAgWFatvx4aUntR+1N 2aCDuAIID8CNIhx40fGfdxVa4Rf7vfZ1e7/mK5lDZVnWwTOJFNouvlILKLcDPNO51R5XKsc1 zxZwI+P1sTpSBI/KtFfphfaN93H3dLiy26D1P8ShFz6IEfTgK4OVWhqCaOe9oTXTwwNzBQ4= X-Enigmail-Draft-Status: N11100 Message-ID: <57754f11-2c65-a2c8-2f6d-bfab0d2f8b53@etsukata.com> Date: Tue, 9 Jul 2019 14:17:12 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/07/08 18:42, Eiichi Tsukata wrote: > > > On 2019/07/08 17:58, Eiichi Tsukata wrote: > >> >> By the way, is there possibility that the WARNING(#GP in execve(2)) which Steven >> previously hit? : https://lore.kernel.org/lkml/20190321095502.47b51356@gandalf.local.home/ >> >> Even if there were, it will *Not* be the bug introduced by this patch series, >> but the bug revealed by this series. >> > > I reproduced with the kernel: > - https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/commit/?h=x86/core&id=057b48d544b384c47ed921f616128b802ab1fdc3 > > Reproducer: > > # echo 1 > events/preemptirq/irq_disable/enable > # echo userstacktrace > trace_options > # service sshd restart > > [ 20.338200] ------------[ cut here ]------------ > [ 20.339471] General protection fault in user access. Non-canonical address? > [ 20.339488] WARNING: CPU: 1 PID: 1957 at arch/x86/mm/extable.c:126 ex_handler_uaccess+0x52/0x60 > [ 20.342550] Modules linked in: > [ 20.343209] CPU: 1 PID: 1957 Comm: systemctl Tainted: G W 5.2.0-rc7+ #48 > [ 20.344935] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-2.fc30 04/01/2014 > [ 20.346688] RIP: 0010:ex_handler_uaccess+0x52/0x60 > [ 20.347667] Code: c4 08 b8 01 00 00 00 5b 5d c3 80 3d b6 8c 94 01 00 75 db 48 c7 c7 b8 e4 6f aa 48 89 75 f0 c6 05 ad > [ 20.351508] RSP: 0018:ffffb28940453688 EFLAGS: 00010082 > [ 20.352707] RAX: 0000000000000000 RBX: ffffffffaa2023c0 RCX: 0000000000000001 > [ 20.354478] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffffaa7dab8d > [ 20.355706] RBP: ffffb28940453698 R08: 0000000000000000 R09: 0000000000000001 > [ 20.356665] R10: 0000000000000000 R11: 0000000000000000 R12: ffffb28940453728 > [ 20.357594] R13: 0000000000000000 R14: 000000000000000d R15: 0000000000000000 > [ 20.358876] FS: 00007fec9fa248c0(0000) GS:ffff921d3d800000(0000) knlGS:0000000000000000 > [ 20.360573] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 20.361792] CR2: 0000000000000004 CR3: 0000000074d4e000 CR4: 00000000000006e0 > [ 20.363300] Call Trace: > [ 20.363830] fixup_exception+0x4a/0x61 > [ 20.364637] __idt_do_general_protection+0x65/0x1d0 > [ 20.365684] do_general_protection+0x1e/0x30 > [ 20.366654] general_protection+0x1e/0x30 > [ 20.367513] RIP: 0010:arch_stack_walk_user+0x7a/0x100 > [ 20.368583] Code: 00 01 1f 00 0f 85 8d 00 00 00 49 8b 87 98 16 00 00 48 83 e8 10 49 39 c6 77 32 41 83 87 d0 15 00 04 > [ 20.372797] RSP: 0018:ffffb289404537d0 EFLAGS: 00010046 > [ 20.374027] RAX: 0000000000000000 RBX: ffff921d383bcb00 RCX: 0074726174736572 > [ 20.375674] RDX: ffff921d38393b84 RSI: 7265732e64687373 RDI: ffffb28940453818 > [ 20.377179] RBP: ffffb28940453808 R08: 0000000000000001 R09: ffff921d3d169c00 > [ 20.378681] R10: 0000000000000b60 R11: ffff921d38393b70 R12: ffffb28940453818 > [ 20.380195] R13: ffffb28940453f58 R14: 0074726174736572 R15: ffff921d383bcb00 > [ 20.381703] ? profile_setup.cold+0x9b/0x9b > [ 20.382604] stack_trace_save_user+0x60/0x7d > [ 20.383520] trace_buffer_unlock_commit_regs+0x17b/0x220 > [ 20.384686] trace_event_buffer_commit+0x6b/0x200 > [ 20.385741] trace_event_raw_event_preemptirq_template+0x7b/0xc0 > [ 20.387067] ? get_page_from_freelist+0x10a/0x13b0 > [ 20.388129] ? __alloc_pages_nodemask+0x178/0x380 > [ 20.389132] trace_hardirqs_off+0xc6/0x100 > [ 20.390006] get_page_from_freelist+0x10a/0x13b0 > [ 20.390997] ? kvm_clock_read+0x18/0x30 > [ 20.391813] ? sched_clock+0x9/0x10 > [ 20.392647] __alloc_pages_nodemask+0x178/0x380 > [ 20.393706] alloc_pages_current+0x87/0xe0 > [ 20.394609] __page_cache_alloc+0xcd/0x110 > [ 20.395491] __do_page_cache_readahead+0xa1/0x1a0 > [ 20.396547] ondemand_readahead+0x220/0x540 > [ 20.397486] page_cache_sync_readahead+0x35/0x50 > [ 20.398511] generic_file_read_iter+0x8d8/0xbd0 > [ 20.399335] ? __might_sleep+0x4b/0x80 > [ 20.400110] ext4_file_read_iter+0x35/0x40 > [ 20.400937] new_sync_read+0x10f/0x1a0 > [ 20.401833] __vfs_read+0x29/0x40 > [ 20.402608] vfs_read+0xc0/0x170 > [ 20.403319] kernel_read+0x31/0x50 The cause was obvious as Linus already said in: https://lore.kernel.org/lkml/CAHk-=whvxJjBBOmQSsrB-xHkc6xm8zGHsBRgpxh14UsEY_g+nw@mail.gmail.com/ stack_trace_save_user() is called after set_fs(KERNEL_DS). I don't know why systemctl alyways hit this, but user space process can make up stack as it like, so we have to check it by ourselves? ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) { mm_segment_t old_fs; ssize_t result; old_fs = get_fs(); set_fs(KERNEL_DS); /* The cast to a user pointer is valid due to the set_fs() */ result = vfs_read(file, (void __user *)buf, count, pos); set_fs(old_fs); return result; } EXPORT_SYMBOL(kernel_read); > [ 20.404128] prepare_binprm+0x150/0x190 > [ 20.404766] __do_execve_file.isra.0+0x4c0/0xaa0 > [ 20.405559] __x64_sys_execve+0x39/0x50 > [ 20.406173] do_syscall_64+0x55/0x1b0 > [ 20.406762] entry_SYSCALL_64_after_hwframe+0x49/0xbe > [ 20.407703] RIP: 0033:0x7fec9f0ee647 > [ 20.408441] Code: ff 76 e0 f7 d8 64 41 89 01 eb d8 0f 1f 84 00 00 00 00 00 f7 d8 64 41 89 01 eb d7 0f 1f 84 00 00 08 > [ 20.411636] RSP: 002b:00007ffe7f316228 EFLAGS: 00000202 ORIG_RAX: 000000000000003b > [ 20.412686] RAX: ffffffffffffffda RBX: 00007fec9f8105a4 RCX: 00007fec9f0ee647 > [ 20.414047] RDX: 00007ffe7f3167d8 RSI: 00007ffe7f316230 RDI: 00007fec9f73cea0 > [ 20.415048] RBP: 00007ffe7f316480 R08: 0000000000000030 R09: 0000000000000001 > [ 20.416076] R10: 00007ffe7f316498 R11: 0000000000000202 R12: 00007fec9f73cea0 > [ 20.417556] R13: 0000000000000001 R14: 0000000000000001 R15: 0000000000000000 > [ 20.419032] irq event stamp: 832 > [ 20.419493] hardirqs last enabled at (831): [] __find_get_block+0xde/0x360 > [ 20.420649] hardirqs last disabled at (832): [] rcu_irq_enter_irqson+0x12/0x30 > [ 20.422179] softirqs last enabled at (436): [] __do_softirq+0x37f/0x472 > [ 20.423286] softirqs last disabled at (291): [] irq_exit+0xb3/0xd0 > [ 20.424296] ---[ end trace cdb84a67edcdc420 ]--- >