Received: by 10.223.164.202 with SMTP id h10csp4703756wrb; Wed, 29 Nov 2017 10:26:27 -0800 (PST) X-Google-Smtp-Source: AGs4zMbHrimVi5POT0sBr+wbLzMx+lwFMPENIAaVbWDNDQzQ4++NeFTiIxIQLH1neRSXn7N9vwYl X-Received: by 10.99.55.30 with SMTP id e30mr3624541pga.156.1511979987339; Wed, 29 Nov 2017 10:26:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511979987; cv=none; d=google.com; s=arc-20160816; b=sN23OvNM1b0Z57FAUZUq4Q8WCy7cFKCY/sy4myU/P4DuKnZAxkRhSZoLN48fz/TXG2 yRNh8wypAramPBLaXEF1M02X4ZjXSH7rsx1X5pMHy8TqazwP34aCbT+t3hzpLzCCCgZ0 6PynWuc8zHUfzhZC0q0/U7Lpkz3nsDMVaKq7iDL757AbqltFrvHpEM/8FDNJqxy3kL6k nKMVw1sX0w5p1qRldjQOo+fzqMijetZqScoUQlqgPTyuluUNECBXRHEVRJ9ZWVgaW21k yrs9Nc18nNKKseCHkkghYhG3oBfA6UDrFoUwfj5VZqjQZvztdSbMas//FABZE+gjtaAz zWNA== 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=yaI95NjcCTzbjN8LOsJRnFxLJfyt3N/Zcp8VbXymxfM=; b=i1FXfofGDM8dQImRynVCNOtssi9JY9Q6dBcL24izXe/l2zI1J9E8uM+6YRpgeoPjOi CwT8pJ8KIlLDI7jQRfWOk0x6lbuLElu4Y8eHrVH4YUcqd/MEsI5rQwCCcDMGgQu86gHH +kBsRPK30MQtQM/R2HPa2lEI+gjGPAnIjE56Gma4OZqPuoXauUQEWvSxuBjng/epI3Xu Eq7qPZ09xqMZzLwW17VVCBzaxmTO3Z9mXuY5mBwUIQK3EJoXQq9v4+h79sDNNbNXi9g2 qN9q9nvnxEnujx6XUhVkUGhDnoXa6h2bnDVIIRu8Cgga2ACr2BhAnsdMvmc8/9rZ42Dt n7WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sYEwhvo2; 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 m7si1596451pgp.669.2017.11.29.10.26.17; Wed, 29 Nov 2017 10:26:27 -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=sYEwhvo2; 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 S935023AbdK2Ryp (ORCPT + 70 others); Wed, 29 Nov 2017 12:54:45 -0500 Received: from mail-yw0-f193.google.com ([209.85.161.193]:40475 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934897AbdK2Ryl (ORCPT ); Wed, 29 Nov 2017 12:54:41 -0500 Received: by mail-yw0-f193.google.com with SMTP id g191so1674021ywe.7 for ; Wed, 29 Nov 2017 09:54:41 -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=yaI95NjcCTzbjN8LOsJRnFxLJfyt3N/Zcp8VbXymxfM=; b=sYEwhvo2OxSrrGNgeg3WqBLE6b66At5QpZ6Dp2kmu+FyhIQQSxcy7tJ4KXlRI9HQq/ 4a7oQWeTHl3OXfSCYli2mQpCg7WABchoQGRXb5vEcn8oRmTCeda/RLjUWmpA//XG1Jn6 h2XrJK1ZrGxMAbsLIOlBlM4ACU0fmvzMzeRY3agUxsUJSjmhkhxpWECgIMYoYDEJFu+o /KlIORH7fJW6rIWTVoaQ45bdlBsxdIg/8lvU9jxIropOluZKOYx/I+O0AtF2zcUm9BFt nA58D+LYo+o8b3nb9+/DLPbDJbUN0SHABNQszJJplyuT+TMMWuFgbANIneR3gQAWSBNB sdYQ== 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=yaI95NjcCTzbjN8LOsJRnFxLJfyt3N/Zcp8VbXymxfM=; b=ZlBeqIO5VBHS5X/+uiliTLMU7UtcfM9rdt4Nok6v7eXPw7ARE7wHbvV53EsAt8P/we zxAh+D2NnmCFqNtdcG810ttxqF1u9dxcid2S2BCffjFJCH5M6zj2NWszJr6DtI31X3eK lADIUOUSFjnqZLYmr3dxaCywNLqlrHRXNLbnKS2+VeuLj701BjFK6eqic/qyU3QQg2zQ 9kClOQkxf3dYWyt5bTCa1iEM1BAQh4Q9TiHfhh4PJ27g0obnxnWmN82fMlUP97YzVqvB vPprNyTtlAZz18eREQQKjgeyrH27l9843yN3DVYf9OoFndJ/5coEiZjnIiiTnC0krOrb yT/w== X-Gm-Message-State: AJaThX6fUpCxMJBM4hotbVxbhp2Mrem6dE4xcQq5n1LYGRX29Jbx89h3 OTGbiVAhgTKOC7tpieUGhSI= X-Received: by 10.13.213.135 with SMTP id x129mr2242522ywd.185.1511978081028; Wed, 29 Nov 2017 09:54:41 -0800 (PST) Received: from big-sky.attlocal.net (104-187-157-211.lightspeed.mdsnwi.sbcglobal.net. [104.187.157.211]) by smtp.gmail.com with ESMTPSA id w199sm1055933yww.33.2017.11.29.09.54.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 09:54:40 -0800 (PST) Date: Wed, 29 Nov 2017 11:54:30 -0600 From: Dennis Zhou To: Fengguang Wu , Ard Biesheuvel , Kees Cook Cc: linux-mm@kvack.org, Tejun Heo , Christoph Lameter , Linus Torvalds , Josef Bacik , linux-kernel@vger.kernel.org, lkp@01.org, Andrey Ryabinin , Mark Rutland Subject: Re: [pcpu] BUG: KASAN: use-after-scope in pcpu_setup_first_chunk+0x1e3b/0x29e2 Message-ID: <20171129175430.GA58181@big-sky.attlocal.net> References: <20171126063117.oytmra3tqoj5546u@wfg-t540p.sh.intel.com> <20171127210301.GA55812@localhost.corp.microsoft.com> <20171128124534.3jvuala525wvn64r@wfg-t540p.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171128124534.3jvuala525wvn64r@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 everyone, I spent a bit of time learning more about this problem as Fengguang was able to determine the root commit f7dd2507893cc3. I reproduced the bug in userspace to make life a bit easier and below the assignment occurs before the unpoison. This is fine if we're sequentially proceeding, but as in the case in percpu, it's calling the function in a for loop causing the assignment to happen after it has been poisoned in the prior iteration. [0.00%]: _1 = (long unsigned int) i_4; _2 = _1 * 16; _3 = p_8 + _2; list_14 = _3; __u = {}; ASAN_MARK (UNPOISON, &__u, 8); __u.__val = list_14; [0.00%]: _24 = __u.__val; ASAN_MARK (POISON, &__u, 8); list_14->prev = list_14; i_13 = i_4 + 1; [0.00%]: # i_4 = PHI if (i_4 <= 9) goto ; [0.00%] else goto ; [0.00%] I don't know how to go about fixing this though. The reproducing code is below and was compiled with gcc-7 and the structleak_plugin. I hope this helps. Thanks, Dennis ---- #include #include #define barrier() #define WRITE_ONCE(x, val) \ ({ \ union { typeof(x) __val; char __c[1]; } __u = \ { .__val = (typeof(x)) (val) }; \ __write_once_size(&(x), __u.__c, sizeof(x)); \ __u.__val; \ }) typedef uint8_t __u8; typedef uint16_t __u16; typedef uint32_t __u32; typedef uint64_t __u64; static inline __attribute__((always_inline)) void __write_once_size(volatile void *p, void *res, int size) { switch (size) { case 1: *(volatile __u8 *)p = *(__u8 *)res; break; case 2: *(volatile __u16 *)p = *(__u16 *)res; break; case 4: *(volatile __u32 *)p = *(__u32 *)res; break; case 8: *(volatile __u64 *)p = *(__u64 *)res; break; default: barrier(); __builtin_memcpy((void *)p, (const void *)res, size); barrier(); } } struct list_head { struct list_head *next, *prev; }; static inline __attribute__((always_inline)) void INIT_LIST_HEAD(struct list_head *list) { WRITE_ONCE(list->next, list); list->prev = list; } int main(int argc, char *argv[]) { struct list_head *p = malloc(10 * sizeof(struct list_head)); int i; for (i = 0; i < 10; i++) { INIT_LIST_HEAD(&p[i]); } free(p); return 0; } From 1585314012664386564@xxx Tue Nov 28 12:47:37 +0000 2017 X-GM-THRID: 1585109275602552972 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread