Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1117887ybm; Tue, 21 May 2019 08:54:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFpJzUJwVOyyKVXJ3lEC4YVlopc/DHrUi0siS/LKJVGteV28xjZjRr6BnfuVWZnbSgCUEg X-Received: by 2002:a63:fc08:: with SMTP id j8mr82596666pgi.432.1558454086720; Tue, 21 May 2019 08:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558454086; cv=none; d=google.com; s=arc-20160816; b=qzsjHz1GVMQUo7E2O9bIa624OVBRfrJo6x+n2dG28Li259IkyLttwC0qyPavaUf/kW PZPKsCPnoe2hx6/dH4ifiEvv1oyW6hLCuujznEinfUlaZM8GL44kcxPBXaE9htANQCT5 B+YQGb2U83ktIGPPBN0IncOCx+aWPFocyRdB0p2NKTUUykKjLFVERTL2Lug3B9UIaS6N hHmaqbqo/9QyQQs1EiZ7KpeTvJerj7NwUgxKJmXuMx5KoYQi+ZrEj2erFzAiErKLX/Xv GABHyZvT/sfU+pwOqrHNha17Y6A6Hi5yTXuPCKNmELGbIEHo1+QXbpAQjgjJMrdL84uo jlhQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=M+Fy+Dv7IAvIp9wM9LD81KQdUDxns6+Ve3Y3gCcA6+w=; b=NmMotvArNaUFfjpzdyI8CjeVCxusdtglba8PbjKSxtIUMCjG5ySRVRcAYFym0SjJkE IDiMIdZjqULlpIzqfQNnlCAEmgK/rdfZ+2eoVpIZNFTX4Tzc+F/dWpDKdo+vuv9oGYME yGKXlEr9CA1ezEwUuWJIceurOdU3ffTwB8y3bCG7ATH8sTS0C4vHmNHa2rEzbuPMzYUX oZ/1dHl5/eDIdQxGCsYzXmAqn9msYISqnAY2Y6Yin5yAjOrsyhJri/K5NWi/79WNp7km t4X9bTdcP1cw+QEw1GTq/1sH8hvt6ItdbjCc7ClKBv+sYgMlGxiGGgcVKVR//CBRSd67 j3IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SCWW9XLd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l62si20741173pga.434.2019.05.21.08.54.31; Tue, 21 May 2019 08:54:46 -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=@google.com header.s=20161025 header.b=SCWW9XLd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728608AbfEUPxJ (ORCPT + 99 others); Tue, 21 May 2019 11:53:09 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:32849 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727941AbfEUPxI (ORCPT ); Tue, 21 May 2019 11:53:08 -0400 Received: by mail-vs1-f66.google.com with SMTP id y6so11471502vsb.0 for ; Tue, 21 May 2019 08:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=M+Fy+Dv7IAvIp9wM9LD81KQdUDxns6+Ve3Y3gCcA6+w=; b=SCWW9XLdsPw9Dbsh5KL6xVyDY0rX4O5d9enGOPhpycV9Y6K9rosydI/Wlk6NyU8Kte BDjViIeiW8pDzy0+pXpuKIfOK6q7lCzsR5o+tsDOcS4oVA/Plo1Z/Gl7Xaw4/S3dfjlP +TYxG53nLwL/Hdxn/s7e8xypiQ2nTrPoW61MZCVDiWXaRdvGPcbHk5weJMjYioOICzdR HDJC8Ks4/5DvyQMaqKCbH20Idmf9eRPgf4NxzUvXhYL1aiewFYDHnFJO8yWGFdC4Sto5 DpzS2u0AHAD5Fl5qXsTv9dmc55eSJa/zwDTnnViImT0urRRTpNpJ3KPIQsiYspU1cWtG Qnjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=M+Fy+Dv7IAvIp9wM9LD81KQdUDxns6+Ve3Y3gCcA6+w=; b=ZNXcHC4GVnzomAYYiqF3OYRdqzW4sysIXwnTv602mGQ18EvFFj2sY272stgz/je06t i7FYV+GzFJJ4QP7kPnn/nrqK9kd4LOUHExKap8T1P13kXZko37aOOemSCCjGfi5ug1so LS0EED22GyHMwYsaIvwO7Z2AZoMSjhl4PqPhHb0BdWkcV2h8nvBj6gIJEP29fZOVlmig bFUEK/V9vPprh1lF4acf5N/TqxpObfLz7tQMQy3n38CaBh1U8PYvQYp2MAOTX5E6TTV7 BxmdjxnlqAQYxtATAJy0EWc6WusdXi9TQiuRhJ1Z9qMDNCznWGvTMdmDwX0S4AXEWBO5 kmdw== X-Gm-Message-State: APjAAAUWduNl3o/fXGOEzeg7WTXCaJ+MNFYM5F4+lqzim1xUGiz4UllF X+0d8kPAE/lCWzVdJP0IQjHlAZ3ovLfORtfAIpMsnQ== X-Received: by 2002:a67:d615:: with SMTP id n21mr26515680vsj.39.1558453987203; Tue, 21 May 2019 08:53:07 -0700 (PDT) MIME-Version: 1.0 References: <20190520154751.84763-1-elver@google.com> In-Reply-To: From: Alexander Potapenko Date: Tue, 21 May 2019 17:52:55 +0200 Message-ID: Subject: Re: [PATCH v2] mm/kasan: Print frame description for stack bugs To: Andrey Ryabinin Cc: Marco Elver , Dmitriy Vyukov , Andrey Konovalov , Andrew Morton , LKML , Linux Memory Management List , kasan-dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 21, 2019 at 5:43 PM Andrey Ryabinin w= rote: > > > > 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 =3D=3D 1 ? "object" : "objects"); > > + > > + while (num_objects--) { > > + unsigned long offset; > > + unsigned long size; > > + > > + /* access offset */ > > + if (!tokenize_frame_descr(&frame_descr, token, sizeof(tok= en), > > + &offset)) > > + return; > > + /* access size */ > > + if (!tokenize_frame_descr(&frame_descr, token, sizeof(tok= en), > > + &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(tok= en), > > + NULL)) > > + return; > > + > > + /* Strip line number, if it exists. */ > > Why? > > > + strreplace(token, ':', '\0'); > > + > > ... > > > + > > + aligned_addr =3D round_down((unsigned long)addr, sizeof(long)); > > + mem_ptr =3D round_down(aligned_addr, KASAN_SHADOW_SCALE_SIZE); > > + shadow_ptr =3D kasan_mem_to_shadow((void *)aligned_addr); > > + shadow_bottom =3D kasan_mem_to_shadow(end_of_stack(current)); > > + > > + while (shadow_ptr >=3D shadow_bottom && *shadow_ptr !=3D KASAN_ST= ACK_LEFT) { > > + shadow_ptr--; > > + mem_ptr -=3D KASAN_SHADOW_SCALE_SIZE; > > + } > > + > > + while (shadow_ptr >=3D shadow_bottom && *shadow_ptr =3D=3D KASAN_= STACK_LEFT) { > > + shadow_ptr--; > > + mem_ptr -=3D KASAN_SHADOW_SCALE_SIZE; > > + } > > + > > I suppose this won't work if stack grows up, which is fine because it gro= ws 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()). So maybe this BUILD_BUG_ON can be added in a separate patch as it's not specific to what Marco is doing here? > > -- > You received this message because you are subscribed to the Google Groups= "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an= email to kasan-dev+unsubscribe@googlegroups.com. > To post to this group, send email to kasan-dev@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgi= d/kasan-dev/ebec4325-f91b-b392-55ed-95dbd36bbb8e%40virtuozzo.com. > For more options, visit https://groups.google.com/d/optout. --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg