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=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 BD658C433E6 for ; Wed, 20 Jan 2021 20:28:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4337F233FC for ; Wed, 20 Jan 2021 20:28:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4337F233FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AF5BA6B0005; Wed, 20 Jan 2021 15:28:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA7AF6B0006; Wed, 20 Jan 2021 15:28:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BD6E6B0007; Wed, 20 Jan 2021 15:28:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 873746B0005 for ; Wed, 20 Jan 2021 15:28:54 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4E42E180AD81F for ; Wed, 20 Jan 2021 20:28:54 +0000 (UTC) X-FDA: 77727292188.24.shoes52_22021bb2755d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 305E41A4A0 for ; Wed, 20 Jan 2021 20:28:54 +0000 (UTC) X-HE-Tag: shoes52_22021bb2755d X-Filterd-Recvd-Size: 5058 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 Jan 2021 20:28:53 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id b8so13170350plx.0 for ; Wed, 20 Jan 2021 12:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fioXcQ/rcCDFe0T/YIUHW/M/p9VSUety2UTjxNg3ziA=; b=bCfQkCywAIsP3lLuxqsl0MQ4KwOBlshIphqvfRTMiI1aefaiNetuMamFqp9X7i1+o9 1TtsFuxQFB8lsmHffvaLidYS/t+vAjbvQmbvthtopcqayQWW7aTWeSErW68yzO+/e7/s mm8mHyRbr9K5B2a05j+T1hkcJt2yxcWFNMmzY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fioXcQ/rcCDFe0T/YIUHW/M/p9VSUety2UTjxNg3ziA=; b=iG9fLjDZLcbXST7Lm4OF6nvca8eDMZ2uEE6h8S9KbCTDN/GlYYpIbvRDO1ysX8gQy2 pEvuiPiybiFZAhlgDgFwclizriQqtYgFz7g20ZBM1EeYJ+GpTnla9vdJJfOMWdkbVlAr xGxSeRUTng7zfCeq8jAtSCVesjYIrDkIPQCvdLY4Ha3QSTM9PxifPM3KOCwrD8Dwew3a AR3Uwq3ySMT5+cfTa4e3mJnYr8mITGv3G4XP44U9zzNRGtFlK8/fvpJVQMlPqFd6aS3L PuXEeVREOBxMorEJDys/mklik25jKEO3OTBblw1QBJa4iRJfHLG5M07D688Ggr06AmW9 IdIQ== X-Gm-Message-State: AOAM5310qPzV6ZfUlzf3k79G9Ipx1BDeHbL/jIFDsXats3LWeJco4ka3 i5nPSnpv/LoKR/5m/+ZskyiQkg== X-Google-Smtp-Source: ABdhPJz3vqbaKQGcB2+3zZJBFP9PcA+uju+6kutWdGzJQdggXuGIMQNlyI67aU9SoP9c4TvAk4Zhwg== X-Received: by 2002:a17:90a:d3c7:: with SMTP id d7mr7441076pjw.169.1611174532698; Wed, 20 Jan 2021 12:28:52 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 145sm3073897pfu.8.2021.01.20.12.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 12:28:51 -0800 (PST) Date: Wed, 20 Jan 2021 12:28:50 -0800 From: Kees Cook To: Randy Dunlap Cc: Matthew Wilcox , Sergey Senozhatsky , Timur Tabi , 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 Subject: Re: [PATCH 0/2] introduce DUMP_PREFIX_UNHASHED for hex dumps Message-ID: <202101201226.A03F16DF24@keescook> References: <20210116220950.47078-1-timur@kernel.org> <20210118182635.GD2260413@casper.infradead.org> <20210119014725.GH2260413@casper.infradead.org> <202101191135.A78A570@keescook> <82e1f2f3-77c3-ffb4-34b2-0e6f23e6195d@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <82e1f2f3-77c3-ffb4-34b2-0e6f23e6195d@infradead.org> 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 Tue, Jan 19, 2021 at 12:18:17PM -0800, Randy Dunlap wrote: > On 1/19/21 11:45 AM, 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: > > Yes, good patch. Should have been like this to begin with IMO. > > > 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); > > Is 'addr' always set here? > It is only conditionally set above. It should be, yes. Though I agree, it's not obvious. ptr_to_hashval() will write to it when returning 0. So if that fails, addr will have 0 written. Both only happen under DUMP_PREFIX_ADDRESS. -- Kees Cook