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=unavailable 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 54598C433DB for ; Tue, 19 Jan 2021 19:57:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2DF123110 for ; Tue, 19 Jan 2021 19:57:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730237AbhAST5a (ORCPT ); Tue, 19 Jan 2021 14:57:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:52108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392147AbhAST4N (ORCPT ); Tue, 19 Jan 2021 14:56:13 -0500 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.