Received: by 10.223.164.202 with SMTP id h10csp2179103wrb; Mon, 27 Nov 2017 13:05:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMY6okP2HppMubIgrc082t5EssKvjBDwojcpGUiHQhPYZkmZGFigEaasGLcc91QSGEDGA4aC X-Received: by 10.98.131.9 with SMTP id h9mr20043821pfe.30.1511816718143; Mon, 27 Nov 2017 13:05:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511816718; cv=none; d=google.com; s=arc-20160816; b=FOk25/3x6meD5fzIhkeAigUt9r0i+9Yw4A9Cv9AKsbJd7sTB+H7LwDRj/G40rogkzv 71IC7usfDqSCn6ERYS+IdNC9QeocB7imeer311xL15vsrdhheidHuXf466XFw3NEYnxD W9noEli5fTHTslHZZaeXjtPVbBL5rT1uK2MBqNPB2JkF6xz96xEpy492EEbvcYtfU5E8 Pyn7V0JVnLdxkNYkUC/6W/uh72W2UIuZC9uAnghpf254ji8q7Sb71YTs0LEt7qadcaLB gDU6PxpuoSkmTyZmKLgJIsQgfp0hfWVhJh+Fw7eEhY1vzMmYeRgkZf1yhSp8ltQGyCEo rBvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=zlMdWzS1kehFsP+3pXwoEjtw/rj/zG1qbMLXVeCjQ6M=; b=obmt8TvmvTuD9uqfIVXFTzQCl2xZL5KwKzou/3NxkkPO/ZIxN6LY3ErsUchHENCxO4 k40M6eLNZCwQGZLwN8DFfoRmcbW7+ol00YsDyyJxnl3sL0ANVtrUsYMglXPXli/uz81R jTCbLl0Kj4clMgj6rSWmvHQlUI5lJY9la2jZ3xr62cRn84aM18/stRRlPe6jTa9AR7zk Bl9M80LwJBlYlE+OLD8yUvbEkcNSi4LQ4esETOiGDWZYIpnCzVylZRmPHVlBvoHyI1U2 UnuybxFXypWM/HwvHcwAWcNVuYZJzEDI4IIrbg8LS/bL1tVm4SLR90iMrGN8s0mIMsPr lp2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gx4SRkEg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si23387876plo.133.2017.11.27.13.04.48; Mon, 27 Nov 2017 13:05:18 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=gx4SRkEg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932209AbdK0VDS (ORCPT + 78 others); Mon, 27 Nov 2017 16:03:18 -0500 Received: from mail-qk0-f195.google.com ([209.85.220.195]:38612 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932101AbdK0VDQ (ORCPT ); Mon, 27 Nov 2017 16:03:16 -0500 Received: by mail-qk0-f195.google.com with SMTP id a142so34332984qkb.5 for ; Mon, 27 Nov 2017 13:03:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zlMdWzS1kehFsP+3pXwoEjtw/rj/zG1qbMLXVeCjQ6M=; b=gx4SRkEgo/LSPqnsAbkfBPVf5SBpVC6qRD1BZJg/lwdYsHiTDeMvSASspW+GOMqZdr HbRzgK98NEYU2QRQFkhihNRUZmhoIz1+6G2DgzQHOwywFzwh7ZDrPtrByJhSFhhuJuAo JKYKE5x9LLPJpTDhsFgFT59JCHkoYwuyC5j50ZWv8Odv1br06IuTHj/xABfJuxbveQX0 JH1O9gUYhKpCsapPoBlNiDfSzKtd3IBbfvBH/XLssTgzsK6F8iGTNzrX+fUJpK0+anR8 N8xm8oQyREVau15hpm+cKH1kyHTczsZiw2BzXbHzT3nIH6HwQ+GHnUePVL7NtydcsMGH WY/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zlMdWzS1kehFsP+3pXwoEjtw/rj/zG1qbMLXVeCjQ6M=; b=QooXahbnx1YuZySZUj5NZ8lfHEiy2WrUfklxLXi1d8i1VWCeFZ5h2opxbgIjnQUeJR neSmLj34uS7hSVeDlNeR0ZBdum+8Hep1ll/ENzx80fDyi+pKPXFAoGOmt1Gr+BHqZna1 6vrVtjDhHclgBZXkumZa5xnyHHIxrhqacB2PqZzW/AfhR3QNwjHlGiJ7O1shHv64h+Fo v4KclFVs/xV/7Y63tkxUkE9kir0JMnq8r5qOrQzkYO1P3jEDJklNbO9Vle+hzuAqpR4G 9ZXWTUxrpDTEiF2Nwzw+7jT5Kyk2qEYa4dsCAUE6TJH31gWwLpCNnPxwUKsy78GtU09H Wb1g== X-Gm-Message-State: AJaThX4ruMHV6ulSZwFW1CPTEhRFDyqVwXRA69E5CUSA6CSlA3dhK33j arVmJHAKwH+9EjEIZ7ihtog= X-Received: by 10.55.163.12 with SMTP id m12mr60367114qke.60.1511816595197; Mon, 27 Nov 2017 13:03:15 -0800 (PST) Received: from localhost.corp.microsoft.com ([2001:4898:8010:1::3fe]) by smtp.gmail.com with ESMTPSA id p8sm15761189qtj.70.2017.11.27.13.03.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 13:03:14 -0800 (PST) Date: Mon, 27 Nov 2017 15:03:01 -0600 From: Dennis Zhou To: Fengguang Wu Cc: linux-mm@kvack.org, Tejun Heo , Christoph Lameter , Linus Torvalds , Josef Bacik , linux-kernel@vger.kernel.org, lkp@01.org Subject: Re: [pcpu] BUG: KASAN: use-after-scope in pcpu_setup_first_chunk+0x1e3b/0x29e2 Message-ID: <20171127210301.GA55812@localhost.corp.microsoft.com> References: <20171126063117.oytmra3tqoj5546u@wfg-t540p.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171126063117.oytmra3tqoj5546u@wfg-t540p.sh.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Fangguang, On Sun, Nov 26, 2017 at 02:31:17PM +0800, Fengguang Wu wrote: > Hello, > > FYI this happens in mainline kernel 4.14.0-13151-g5a78775. > This looks like a new regression after 4.14. I have reproduced this with the commit and scripts attached. The offending line is the INIT_LIST_HEAD call in the for loop below. Both pcpu_nr_slots and pcpu_slot are global variables. pcpu_nr_slots = __pcpu_size_to_slot(pcpu_unit_size) + 2; pcpu_slot = memblock_virt_alloc( pcpu_nr_slots * sizeof(pcpu_slot[0]), 0); for (i = 0; i < pcpu_nr_slots; i++) INIT_LIST_HEAD(&pcpu_slot[i]); The management of the percpu slots was not changed with the bitmap allocator in v4.14. That line actually is from Tejun's rewrite in 2009, commit fbf59bc9d. Just to be safe, I did revert my commits and reproduced the same error. GCC version: gcc-7 (Ubuntu 7.2.0-1ubuntu1~16.04) 7.2.0 > [ 0.000000] ================================================================== > [ 0.000000] BUG: KASAN: use-after-scope in pcpu_setup_first_chunk+0x1e3b/0x29e2: > pcpu_setup_first_chunk at mm/percpu.c:2118 (discriminator 3) > [ 0.000000] Write of size 8 at addr ffffffff83c07d38 by task swapper/0 > [ 0.000000] > [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.14.0-13151-g5a78775 #2 > [ 0.000000] Call Trace: > [ 0.000000] print_address_description+0x2d/0x3d0: > print_address_description at mm/kasan/report.c:253 > [ 0.000000] ? pcpu_setup_first_chunk+0x1e3b/0x29e2: > pcpu_setup_first_chunk at mm/percpu.c:2118 (discriminator 3) > [ 0.000000] kasan_report+0x1f4/0x3b0: > kasan_report_error at mm/kasan/report.c:352 > (inlined by) kasan_report at mm/kasan/report.c:409 > [ 0.000000] pcpu_setup_first_chunk+0x1e3b/0x29e2: > pcpu_setup_first_chunk at mm/percpu.c:2118 (discriminator 3) Interestingly, while the INIT_LIST_HEAD call is what is causing problems, I manually unrolled the loop and the location of the bug changed. This happens both inside and outside of the for loop as long as it only has 1 iteration. [ 0.000000] ================================================================== [ 0.000000] BUG: KASAN: use-after-scope in pageset_init (/users/dennisz/linux-linus//include/linux/listh:28 /users/dennisz/linux-linus/mm/page_allocc:5509) [ 0.000000] Write of size 8 at addr ffffffff83c07dc8 by task swapper/0 [ 0.000000] [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.14.0-13151-g5a78775-dirty #53 [ 0.000000] Call Trace: [ 0.000000] print_address_description (/users/dennisz/linux-linus/mm/kasan/reportc:253) [ 0.000000] ? pageset_init (/users/dennisz/linux-linus//include/linux/listh:28 /users/dennisz/linux-linus/mm/page_allocc:5509) [ 0.000000] kasan_report (/users/dennisz/linux-linus/mm/kasan/reportc:352 /users/dennisz/linux-linus/mm/kasan/reportc:409) [ 0.000000] pageset_init (/users/dennisz/linux-linus//include/linux/listh:28 /users/dennisz/linux-linus/mm/page_allocc:5509) [ 0.000000] ? is_free_buddy_page (/users/dennisz/linux-linus/mm/page_allocc:5500) [ 0.000000] build_all_zonelists_init (/users/dennisz/linux-linus/mm/page_allocc:5483 /users/dennisz/linux-linus/mm/page_allocc:5496 /users/dennisz/linux-linus/mm/page_allocc:5515 /users/dennisz/linux-linus/mm/page_allocc:5262) [ 0.000000] build_all_zonelists (/users/dennisz/linux-linus/mm/page_allocc:5277) [ 0.000000] start_kernel (/users/dennisz/linux-linus/init/mainc:546) [ 0.000000] ? thread_stack_cache_init+0x2e/0x2e [ 0.000000] ? memcpy_orig (/users/dennisz/linux-linus/arch/x86/lib/memcpy_64S:106) [ 0.000000] secondary_startup_64 (/users/dennisz/linux-linus/arch/x86/kernel/head_64S:237) [ 0.000000] [ 0.000000] [ 0.000000] Memory state around the buggy address: [ 0.000000] ffffffff83c07c80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0.000000] ffffffff83c07d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0.000000] >ffffffff83c07d80: 00 00 00 00 00 f1 f1 f1 f1 f8 f2 f2 f2 00 00 00 [ 0.000000] ^ [ 0.000000] ffffffff83c07e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0.000000] ffffffff83c07e80: 00 00 00 00 00 00 00 00 00 00 00 00 f8 00 00 00 [ 0.000000] ================================================================== Next, I did a partial unroll where the loop went through 2 iterations and then manually called INIT_LIST_HEAD for the remainder, the bug returns. I've left this trace out as it is the same as reported by Fangguang. I'm not familiar with the details of KASAN, but it seems that there is a weird interaction with KASAN use-after-scope and subsequent invocations of inlined functions called from inside a for loop. I don't think I have enough background to continue debugging this myself, who would be a good person to loop in for help? Thanks, Dennis From 1585109275602552972@xxx Sun Nov 26 06:33:24 +0000 2017 X-GM-THRID: 1585109275602552972 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread