Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934257AbcLTJnn convert rfc822-to-8bit (ORCPT ); Tue, 20 Dec 2016 04:43:43 -0500 Received: from mail1.bemta12.messagelabs.com ([216.82.251.16]:18573 "EHLO mail1.bemta12.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933851AbcLTJnl (ORCPT ); Tue, 20 Dec 2016 04:43:41 -0500 X-Greylist: delayed 428 seconds by postgrey-1.27 at vger.kernel.org; Tue, 20 Dec 2016 04:43:40 EST X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCIsWRWlGSWpSXmKPExsWS8eIhk27D74g Ig4NH2C0u75rDZnFvzX9WByaPTZ8msXt83iQXwBTFmpmXlF+RwJrx4PsW1oIW8YqW0x1MDYzP BLsYuTiEBJ4wSjxZtI4JwlnIKHFoagNrFyMHB5uAusTvE3wgpohArsTB5mQQU1ggSOLJJYkuR k6gaLjEgoX32SFsPYnGsw1sIDaLgKrE362nwWxeAS+JDY1PwGxGAVmJaY/uM4HYzALiEnOnzW IFsSUEBCSW7DnPDGGLSrx8/A/sAAkBeYktswQhynUkFuz+xAZha0ssW/iaGWK8oMTJmU9YJjA KzkIydRaSlllIWmYhaVnAyLKKUaM4tagstUjXyFAvqSgzPaMkNzEzR9fQ0EgvN7W4ODE9NScx qVgvOT93EyMwtOsZGBh3MLZP9zrEKMnBpCTKu58nIkKILyk/pTIjsTgjvqg0J7X4EKMMB4eSB C/3L6CcYFFqempFWmYOMMpg0hIcPEoivOd/AqV5iwsSc4sz0yFSpxgVpcR5j4AkBEASGaV5cG 2wyL7EKCslzMvIwMAgxFOQWpSbWYIq/4pRnINRSZj3CsgUnsy8Erjpr4AWMwEtXtgdDrK4JBE hJdXAOKcrX3jmKkuzNd/quesyF7RUfWiMyudapXbd9Ircn/iXpcybH/0wuHaIKVll6kproX0P a1x5PRxeKEZm/XH6flL5WseW1PqvNz4qfDi+fcn9CoNXp/l95xz7v0PcVtm838m+L7roibCqs suJrpBFry/zmf5+ILSb9eHuhQ93pk2KTpH9p9MuqMRSnJFoqMVcVJwIAIwOfF7nAgAA X-Env-Sender: caods1@lenovo.com X-Msg-Ref: server-9.tower-190.messagelabs.com!1482226558!70753605!1 X-Originating-IP: [104.232.225.2] X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked From: Dashi DS1 Cao To: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: A small window for a race condition in mm/rmap.c:page_lock_anon_vma_read Thread-Topic: A small window for a race condition in mm/rmap.c:page_lock_anon_vma_read Thread-Index: AdJaoiBI0AeNZbJZSQCgF3f04k/2og== Date: Tue, 20 Dec 2016 09:32:27 +0000 Message-ID: <23B7B563BA4E9446B962B142C86EF24ADBD62C@CNMAILEX03.lenovo.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.96.19.89] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2922 Lines: 60 I've collected four crash dumps with similar backtrace. PID: 247 TASK: ffff881fcfad8000 CPU: 14 COMMAND: "kswapd1" #0 [ffff881fcfad7978] machine_kexec at ffffffff81051e9b #1 [ffff881fcfad79d8] crash_kexec at ffffffff810f27e2 #2 [ffff881fcfad7aa8] oops_end at ffffffff8163f448 #3 [ffff881fcfad7ad0] die at ffffffff8101859b #4 [ffff881fcfad7b00] do_general_protection at ffffffff8163ed3e #5 [ffff881fcfad7b30] general_protection at ffffffff8163e5e8 [exception RIP: down_read_trylock+9] RIP: ffffffff810aa9f9 RSP: ffff881fcfad7be0 RFLAGS: 00010286 RAX: 0000000000000000 RBX: ffff882b47ddadc0 RCX: 0000000000000000 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 91550b2b32f5a3e8 RBP: ffff881fcfad7be0 R8: ffffea00ecc28860 R9: ffff883fcffeae28 R10: ffffffff81a691a0 R11: 0000000000000001 R12: ffff882b47ddadc1 R13: ffffea00ecc28840 R14: 91550b2b32f5a3e8 R15: ffffea00ecc28840 ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0000 #6 [ffff881fcfad7be8] page_lock_anon_vma_read at ffffffff811a3365 #7 [ffff881fcfad7c18] page_referenced at ffffffff811a35e7 #8 [ffff881fcfad7c90] shrink_active_list at ffffffff8117e8cc #9 [ffff881fcfad7d48] balance_pgdat at ffffffff81180288 #10 [ffff881fcfad7e20] kswapd at ffffffff81180813 #11 [ffff881fcfad7ec8] kthread at ffffffff810a5b8f #12 [ffff881fcfad7f50] ret_from_fork at ffffffff81646a98 I suspect my customer hits into a small window of a race condition in mm/rmap.c: page_lock_anon_vma_read. struct anon_vma *page_lock_anon_vma_read(struct page *page) { struct anon_vma *anon_vma = NULL; struct anon_vma *root_anon_vma; unsigned long anon_mapping; rcu_read_lock(); anon_mapping = (unsigned long)READ_ONCE(page->mapping); if ((anon_mapping & PAGE_MAPPING_FLAGS) != PAGE_MAPPING_ANON) goto out; if (!page_mapped(page)) goto out; anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON); root_anon_vma = READ_ONCE(anon_vma->root); if (down_read_trylock(&root_anon_vma->rwsem)) { /* * If the page is still mapped, then this anon_vma is still * its anon_vma, and holding the mutex ensures that it will * not go away, see anon_vma_free(). */ if (!page_mapped(page)) { up_read(&root_anon_vma->rwsem); anon_vma = NULL; } goto out; } ... } Between the time the two "page_mapped(page)" are checked, the address (anon_mapping - PAGE_MAPPING_ANON) is unmapped! However it seems that anon_vma->root could still be read in but the value is wild. So the kernel crashes in down_read_trylock. But it's weird that all the "struct page" has its member "_mapcount" still with value 0, not -1, in the four crashes. Thanks, Dashi Cao