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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 8814DC433E0 for ; Tue, 19 Jan 2021 19:55:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D46BB2310C for ; Tue, 19 Jan 2021 19:55:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D46BB2310C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2B3046B0005; Tue, 19 Jan 2021 14:55:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2639D6B0006; Tue, 19 Jan 2021 14:55:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 151E46B0007; Tue, 19 Jan 2021 14:55:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id F2DB86B0005 for ; Tue, 19 Jan 2021 14:55:34 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B055B180AD822 for ; Tue, 19 Jan 2021 19:55:34 +0000 (UTC) X-FDA: 77723579388.19.wish15_180b0c227554 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 81BA21AD1B3 for ; Tue, 19 Jan 2021 19:55:34 +0000 (UTC) X-HE-Tag: wish15_180b0c227554 X-Filterd-Recvd-Size: 3793 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 Jan 2021 19:55:33 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 5233423104; Tue, 19 Jan 2021 19:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611086132; bh=5OONEVY+UXy6TZlBP5jOksmHE3/6yEFjijufZCWKRSk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=mM6GekNo7M7nZMz3BIKqqTmHjNWaC+UHwfBf/Ym4I4WwPC4O8j/MXCfsZGMA4ABeg cSR04o38SZOmkPccHe+BYj6DmehUbJP+kMDnqsmmHMYX8LYUA6/M1DKIHPd5u7P/Vk 2WOqFC8yWm7ykWYWlyzGkpUyAJHkEFNvUCnWZG1CgAI0NH47RSJWjsPqop8kU6R09+ 7HvpHlS8r2BMv74iDfrQ1i2befSznTzu74rUbq38byvL8S4oOOexaUt4QwekjFZrvH EjKS0NAfboOkX1Finu1tpqNThU4ahql1a6MHnw0c21vEXtoeXxay335c8kMCe7uBwn 7Ov6djH6k3J1Q== Subject: Re: [PATCH 0/2] introduce DUMP_PREFIX_UNHASHED for hex dumps To: Kees Cook , Matthew Wilcox Cc: Sergey Senozhatsky , Andrew Morton , linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, Petr Mladek , roman.fietze@magna.com, Steven Rostedt , John Ogness , linux-mm@kvack.org, Akinobu Mita References: <20210116220950.47078-1-timur@kernel.org> <20210118182635.GD2260413@casper.infradead.org> <20210119014725.GH2260413@casper.infradead.org> <202101191135.A78A570@keescook> From: Timur Tabi Message-ID: <29122c86-bfea-2f25-d111-00641cc660ba@kernel.org> Date: Tue, 19 Jan 2021 13:55:29 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <202101191135.A78A570@keescook> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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 1/19/21 1:45 PM, Kees Cook wrote: > How about this so the base address is hashed once, with the offset added > to it for each line instead of each line having a "new" hash that makes > no sense: > > diff --git a/lib/hexdump.c b/lib/hexdump.c > index 9301578f98e8..20264828752d 100644 > --- a/lib/hexdump.c > +++ b/lib/hexdump.c > @@ -242,12 +242,17 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, > const void *buf, size_t len, bool ascii) > { > const u8 *ptr = buf; > + const u8 *addr; > int i, linelen, remaining = len; > unsigned char linebuf[32 * 3 + 2 + 32 + 1]; > > if (rowsize != 16 && rowsize != 32) > rowsize = 16; > > + if (prefix_type == DUMP_PREFIX_ADDRESS && > + ptr_to_hashval(ptr, &addr)) > + addr = 0; > + > for (i = 0; i < len; i += rowsize) { > linelen = min(remaining, rowsize); > remaining -= rowsize; > @@ -258,7 +263,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, > switch (prefix_type) { > case DUMP_PREFIX_ADDRESS: > printk("%s%s%p: %s\n", > - level, prefix_str, ptr + i, linebuf); > + level, prefix_str, addr + i, linebuf); Well, this is better than nothing, but not by much. Again, as long as %px exists for printk(), I just cannot understand any resistance to allowing it in print_hex_dump(). Frankly, I think this patch and my patch should both be added. During debugging, it's very difficult if not impossible to work with hashed addresses. I use print_hex_dump() with an unhashed address all the time, either by applying my patch to my own kernel or just replacing the %p with %px.