Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1265979ybm; Tue, 21 May 2019 11:10:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYN0itBNhyJxqqcgmGrfY+uqrdqbo8GO4vHAj09Cp8YbK2oSEzXXov9OOWHUjKAIJGU+bg X-Received: by 2002:a65:4907:: with SMTP id p7mr83164284pgs.288.1558462227155; Tue, 21 May 2019 11:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558462227; cv=none; d=google.com; s=arc-20160816; b=Xar9BuzKbLO5zC5VNegUuLLSUFnRcX0zywzezk5ZWpavaaMJtnRQoxizvGDAwRPwlf SldXMTm/Z4JGtRbHdz5fIQaVE2puUoeB5G5AIjdNSxsOo1bpw68k4A51P23nZWJauasR 8rxvNxTkCgz8UBYeCr4Ahdd7bECvorARJFhjeHDlpQO5mhuit5L9y4qxeHdmDFBNKW3/ k5rpVhqgXWFZmpRNLXepWMvE4KPxMELri1oBpv2SRMj3PIorWygrHJm4kFlDcYPpHzWR vGUwqevjMWkCgjPNOyqg3fL7sAqbn11s1CZhZJ4BFPcD+WBWwI1/fS+q4fkkAj+k8dib ZG2Q== 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:from:references:cc:to:subject; bh=VW5Gqms6RUuTMruuwhVT0/XMTieYuN/y7XeRBAJOnCU=; b=K7tmkMAxu//mCIb0iyqZ4KNGYmdUW3jbl1TUtTTT88ixRPj9UcJwAKANQ0cJ5LEmvU 9wWA6XNgc0vdnei0ZaGZHKH0d+SNXV/GCrYmmuzItLkwZ2wV8OaCNHub6FI0xhWHPB6N 63aY+ejBD81YyNzuI2gEe1wpvQJ6WJTusp4LPv3ow6xg8QT4ZcgS+NaHzZy7xv/Tk6FH jm+SuyV7CwKyx1VETelaU1g8etcWobLwG6KGuoZpFHD2XrEurDya2BTaeFa6FMFpiryE cGBW0Zr5zWcfpu2hIzlS6tFOm9w4RgSYEZkRO07vwu4mlzGheoYGxaylWidnt3ebwgmW hqbA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d191si21040828pga.454.2019.05.21.11.10.11; Tue, 21 May 2019 11:10:27 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729242AbfEUSHb (ORCPT + 99 others); Tue, 21 May 2019 14:07:31 -0400 Received: from relay.sw.ru ([185.231.240.75]:43392 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729225AbfEUSHb (ORCPT ); Tue, 21 May 2019 14:07:31 -0400 Received: from [172.16.25.12] by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hT9Ad-00083b-Gp; Tue, 21 May 2019 21:07:27 +0300 Subject: Re: [PATCH v2] mm/kasan: Print frame description for stack bugs To: Marco Elver , Alexander Potapenko Cc: Dmitriy Vyukov , Andrey Konovalov , Andrew Morton , LKML , Linux Memory Management List , kasan-dev References: <20190520154751.84763-1-elver@google.com> From: Andrey Ryabinin Message-ID: <292035fd-64b7-1767-3e8a-3a6cb50298b5@virtuozzo.com> Date: Tue, 21 May 2019 21:07:45 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/21/19 7:07 PM, Marco Elver wrote: > On Tue, 21 May 2019 at 17:53, Alexander Potapenko wrote: >> >> On Tue, May 21, 2019 at 5:43 PM Andrey Ryabinin wrote: >>> >>> On 5/20/19 6:47 PM, Marco Elver wrote: >>> >>>> +static void print_decoded_frame_descr(const char *frame_descr) >>>> +{ >>>> + /* >>>> + * We need to parse the following string: >>>> + * "n alloc_1 alloc_2 ... alloc_n" >>>> + * where alloc_i looks like >>>> + * "offset size len name" >>>> + * or "offset size len name:line". >>>> + */ >>>> + >>>> + char token[64]; >>>> + unsigned long num_objects; >>>> + >>>> + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), >>>> + &num_objects)) >>>> + return; >>>> + >>>> + pr_err("\n"); >>>> + pr_err("this frame has %lu %s:\n", num_objects, >>>> + num_objects == 1 ? "object" : "objects"); >>>> + >>>> + while (num_objects--) { >>>> + unsigned long offset; >>>> + unsigned long size; >>>> + >>>> + /* access offset */ >>>> + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), >>>> + &offset)) >>>> + return; >>>> + /* access size */ >>>> + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), >>>> + &size)) >>>> + return; >>>> + /* name length (unused) */ >>>> + if (!tokenize_frame_descr(&frame_descr, NULL, 0, NULL)) >>>> + return; >>>> + /* object name */ >>>> + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), >>>> + NULL)) >>>> + return; >>>> + >>>> + /* Strip line number, if it exists. */ >>> >>> Why? > > The filename is not included, and I don't think it adds much in terms > of ability to debug; nor is the line number included with all > descriptions. I think, the added complexity of separating the line > number and parsing is not worthwhile here. Alternatively, I could not > pay attention to the line number at all, and leave it as is -- in that > case, some variable names will display as "foo:123". > Either way is fine by me. But explain why in comment if you decide to keep current code. Something like /* Strip line number cause it's not very helpful. */ >>> >>>> + strreplace(token, ':', '\0'); >>>> + >>> >>> ... >>> >>>> + >>>> + aligned_addr = round_down((unsigned long)addr, sizeof(long)); >>>> + mem_ptr = round_down(aligned_addr, KASAN_SHADOW_SCALE_SIZE); >>>> + shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr); >>>> + shadow_bottom = kasan_mem_to_shadow(end_of_stack(current)); >>>> + >>>> + while (shadow_ptr >= shadow_bottom && *shadow_ptr != KASAN_STACK_LEFT) { >>>> + shadow_ptr--; >>>> + mem_ptr -= KASAN_SHADOW_SCALE_SIZE; >>>> + } >>>> + >>>> + while (shadow_ptr >= shadow_bottom && *shadow_ptr == KASAN_STACK_LEFT) { >>>> + shadow_ptr--; >>>> + mem_ptr -= KASAN_SHADOW_SCALE_SIZE; >>>> + } >>>> + >>> >>> I suppose this won't work if stack grows up, which is fine because it grows up only on parisc arch. >>> But "BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROUWSUP))" somewhere wouldn't hurt. >> Note that KASAN was broken on parisc from day 1 because of other >> assumptions on the stack growth direction hardcoded into KASAN >> (e.g. __kasan_unpoison_stack() and __asan_allocas_unpoison()). It's not broken, it doesn't exist. >> So maybe this BUILD_BUG_ON can be added in a separate patch as it's >> not specific to what Marco is doing here? > I think it's fine to add it in this patch because BUILD_BUG_ON() is just a hint for developers that this particular function depends on growing down stack. So it's more a property of the function rather than KASAN in general. Other functions you mentioned can be marked with BUILD_BUG_ON()s as well, but not in this patch indeed. > Happy to send a follow-up patch, or add here. Let me know what you prefer. > Send v3 please.