From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40AA8CA9EAE for ; Tue, 29 Oct 2019 14:00:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E4D3020862 for ; Tue, 29 Oct 2019 14:00:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DivNkVWF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4D3020862 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 989A06B0008; Tue, 29 Oct 2019 10:00:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93B196B000A; Tue, 29 Oct 2019 10:00:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 802EE6B000C; Tue, 29 Oct 2019 10:00:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id 5F3E06B0008 for ; Tue, 29 Oct 2019 10:00:07 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 1C7C2440F for ; Tue, 29 Oct 2019 14:00:07 +0000 (UTC) X-FDA: 76096981254.20.soup31_58438b5f40a39 X-HE-Tag: soup31_58438b5f40a39 X-Filterd-Recvd-Size: 6998 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Oct 2019 14:00:06 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id n15so13736742wrw.13 for ; Tue, 29 Oct 2019 07:00:06 -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=51+33HKXglD7ivoCUOCWHJsBqgXdGCD+uwczjKUfXdA=; b=DivNkVWFGTjIhWWqWCE0rPiaWDRGsnczusHdewYpoQRHj0qp7AhsiX5Qz4wXqf1MOj jfds8eyMEUlQB1jDofh5jPvWcXzBuTfx9Dea0rRsfbZGoXwTIvE91aX7M5cM00vGakgK 0G3MJUqFcjgVhIGjx5plVv9xy1nh6XDXXI5NRfxYJKMRl2B8hOeHt9JDMZRPRyHwd13A ihZs/12+h648e5xk2M4GdM8zbJtm3jc6ceTNcf07CudrWdRBhjqMw0y3NQ3x2yGp2RtN LNRb35DoCggrRgAkPpg99FA0N9uOVlXoCanJSZQc5Us+TQRMTSvEHaX0viCkyat+qk1W xVUg== 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=51+33HKXglD7ivoCUOCWHJsBqgXdGCD+uwczjKUfXdA=; b=IB5h6qoz+NCcah58JvhaiA3TZgk1c3Z5hGkGlJv5N/Q5nFtoGWrv1U4p/5B5jjCphv ERwg+xPuGJVtLyXTk+Py3F6lJuWieCd5ERSvcFWEBZyC72XuSswt9ZgcppXBdVQ6Qfvl RhpcGgePaYungt6TlLYS5J2Fh/fQMY5n498BrKatNwoZO8qFSjhWcv74ZEtggU/jUdh8 WmLDQkfWVFza5OqdBOtqRzEnxAO8nhmlOVJ0JLpfKUFvriJ79T62jrD47wSrWS2ujkYG 72OAZ+0Ijr9W7OZTT8PO9UuO9IdWjifjPxNKsvJr0iPANGKYq9HHGPY4/B3b8aX4vaNf /OLA== X-Gm-Message-State: APjAAAUZHCxp4AhSh4Pmy3WMZk1ZlNOiujhmC6hyQOXabCVYl9j8LXki LIBWpbZrLXRD79qBXiBkYmVAaJP6HaL9UpPueQA1VQ== X-Google-Smtp-Source: APXvYqz4Tlk43Ikln38JNadG1QHJQjX/GYRgAkM3a0E10E43sYMUkqK45MZFjz59rtW1OalAqTImylrAa0B2ic3+76c= X-Received: by 2002:adf:cd87:: with SMTP id q7mr21082024wrj.216.1572357604500; Tue, 29 Oct 2019 07:00:04 -0700 (PDT) MIME-Version: 1.0 References: <20191018094304.37056-1-glider@google.com> <20191018094304.37056-20-glider@google.com> <20191021092551.lf5hadk2kigzwveo@pathway.suse.cz> In-Reply-To: <20191021092551.lf5hadk2kigzwveo@pathway.suse.cz> From: Alexander Potapenko Date: Tue, 29 Oct 2019 14:59:53 +0100 Message-ID: Subject: Re: [PATCH RFC v1 19/26] kmsan: call KMSAN hooks where needed To: Petr Mladek Cc: Andrew Morton , Greg Kroah-Hartman , Eric Dumazet , Wolfram Sang , Vegard Nossum , Dmitry Vyukov , Linux Memory Management List , Sergey Senozhatsky , Steven Rostedt Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Oct 21, 2019 at 11:25 AM Petr Mladek wrote: > > On Fri 2019-10-18 11:42:57, glider@google.com wrote: > > Insert KMSAN hooks that check for potential memory errors and/or make > > necessary bookkeeping changes: > > - allocate/split/deallocate metadata pages in > > alloc_pages()/split_page()/free_page(); > > - clear page shadow and origins in clear_page(), copy_user_highpage(); > > - copy page metadata in copy_highpage(), wp_page_copy(); > > - handle vmap()/vunmap()/iounmap(); > > - handle task creation and deletion; > > - handle vprintk(); > > I looked only at the printk part. > > > - call softirq entry/exit hooks in kernel/softirq.c; > > - check/initialize memory sent to/read from USB, I2C, and network > > > > Signed-off-by: Alexander Potapenko > > To: Alexander Potapenko > > Cc: Andrew Morton > > Cc: Greg Kroah-Hartman > > Cc: Eric Dumazet > > Cc: Wolfram Sang > > Cc: Petr Mladek > > Cc: Vegard Nossum > > Cc: Dmitry Vyukov > > Cc: linux-mm@kvack.org > > Could you please add into CC also the other printk co-maitainers? Will do in the next version of this patch. > + Sergey Senozhatsky > + Steven Rostedt > > > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > > index ca65327a6de8..f77fdcb5f861 100644 > > --- a/kernel/printk/printk.c > > +++ b/kernel/printk/printk.c > > @@ -1914,7 +1914,12 @@ int vprintk_store(int facility, int level, > > * The printf needs to come first; we need the syslog > > * prefix which might be passed-in as a parameter. > > */ > > - text_len =3D vscnprintf(text, sizeof(textbuf), fmt, args); > > + /* > > + * We've checked the printk arguments in vprintk_emit() already. > > + * Initialize |text_len| to prevent the errors from spreading. > > + */ > > + text_len =3D KMSAN_INIT_VALUE(vscnprintf(text, sizeof(textbuf), f= mt, > > + args)); > > I am a bit confused by the comment. Fixed in v2. > What is the exact meaning of KMSAN_INIT_VALUE(), please? Hope it'll be clear from the "kmsan: add KMSAN runtime" patch. In fact KMSAN_INIT_VALUE is a wrapper that turns an uninitialized value into an initialized one: https://github.com/google/kmsan/blob/3207d604ad68f7e5defdbbd6e63cb97750f380= c1/include/linux/kmsan-checks.h#L58 It passes the value into an identity function that always returns unpoisoned values. As a result, from now on text_len is considered initialized, regardless of what vscnprintf() returned. Without KMSAN_INIT_VALUE the tool will report a huge number of errors when text_len is used in vprintk_store() and log_output(). > Does it prevent checking fmt again? > Does make the text_len variable special? In which way? > > > > /* mark and strip a trailing newline */ > > if (text_len && text[text_len-1] =3D=3D '\n') { > > @@ -1972,6 +1977,7 @@ asmlinkage int vprintk_emit(int facility, int lev= el, > > boot_delay_msec(level); > > printk_delay(); > > > > + kmsan_handle_vprintk(&fmt, args); > > What does this function, please? > Could I find more details in another patch? > > > /* This stops the holder of console_sem just where we want him */ > > logbuf_lock_irqsave(flags); > > curr_log_seq =3D log_next_seq; > > Best Regards, > Petr --=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