Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4793306ybb; Tue, 7 Apr 2020 14:46:58 -0700 (PDT) X-Google-Smtp-Source: APiQypKAspoTfu75PKMLF2vGAgoHbOcM18+UbHLUe/M62zRw7mykUt5jRo7xe7yBuzjuAM/PN0bp X-Received: by 2002:a9d:247:: with SMTP id 65mr3364559otb.364.1586296018582; Tue, 07 Apr 2020 14:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586296018; cv=none; d=google.com; s=arc-20160816; b=M+f8LN8zIU6vqZmGKaKjEePjJLVzyHnMqn5f0ZDu3KgEHbsp4v1XTa445xY5eDyrS1 yIbRom39oaffu4snkTLhF5UQaeG/p/fCKJ3In1Xf1d0jo8nSTq2AQ/xEp3uVUz48BsLL wfyQ18n6RqJ1Ajh7ffDiB6d/JAm5ctaQrENOpo6eedpktoyMQmDCB7SwUbpWWaj8WJyQ a0RLRlRzFXcZFhb1wKDeiGoJEXbDqQbb2a5yZaDA1HRxew47clU2yqT9r3M9z4aG+50K BKVTmhq4RQYj+eaxUPY+RJ2oVYr1zbN/3+5CNlw70BvGk8jpJGEwZ8Hhk2sXV9gx3iEX f2rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jJS9snVu5vDf/p1WAVPSGxLik8Jf/0ksqz7dpeYuVlU=; b=cAp6USo165t8utpMhX8RFBEOIozDuJi2J20BwYi7CZLPzGy4Jqq9pNyUpzfWxzMDec QAm9Ss+z1EfVgmuHBDWmoP4in/tfzUuyK9YtnWtZtWCBgysTSaDc9wlNM1lPmbUCcyb3 EL1/98B8B1oOe1B2ZqLo1S0L+qWp3tTjbPAlUMLX9hyuQLJ0wVDXU9zWc5PYowlqExCS 0xE6i81qQneyrWP+fMczSkN6AVz/9K5REHCDPtCFYQF+R3egSmT1uPha9XXaCru9eRUk q8/rQxyaHKqTtgn8IWFXziNUkpM7T/S1w90sDGf+KkMPociAKhL+QT1UA1TNPz6SU4F4 XOLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fS78i4Mi; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si1184894oiy.229.2020.04.07.14.46.43; Tue, 07 Apr 2020 14:46:58 -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=@gmail.com header.s=20161025 header.b=fS78i4Mi; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgDGVpa (ORCPT + 99 others); Tue, 7 Apr 2020 17:45:30 -0400 Received: from mail-il1-f196.google.com ([209.85.166.196]:42135 "EHLO mail-il1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726395AbgDGVpa (ORCPT ); Tue, 7 Apr 2020 17:45:30 -0400 Received: by mail-il1-f196.google.com with SMTP id f16so4763735ilj.9 for ; Tue, 07 Apr 2020 14:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jJS9snVu5vDf/p1WAVPSGxLik8Jf/0ksqz7dpeYuVlU=; b=fS78i4MiF11WQ1eDDbkUkpEmIGiB3eNrqvl2Sjls0ugnNCKQdcxHdy8D3OYKN57QZi HK6gOz+s4zjZhzR/EWwXOwOfG/3Gpym9YFE1h6wppOMa4bDPRnF9PzM8sJ177pPDVYR5 RYidyWH+WJerrXxcPWO/BACpmG4MAo01QmTEcosV31B5JvDvdXdjKCHg/0QmQf55tzyS owA2AJaRV6amevWuhgRpujkKGdFvNoSvqataB8Mh794PrVxfZmOAHaiXMFQoww6HNaiZ BPtQPDQaVYgXsASeCgnoF8PTB8FpHlRERGFVsif2FiC7SOO6pHNdlYT4DKMi6IMYlNE3 uqmw== 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; bh=jJS9snVu5vDf/p1WAVPSGxLik8Jf/0ksqz7dpeYuVlU=; b=dJbkXVQNCRjkbc/X+5ZLrxeeNZoRWbnmspwwp8StdUISzmbEN+1pkifohb6cYfHix3 YdlFbmOjj2vE4mN0xnKLPZUNWwPEzveTVRkqV8NlD+XXbacuZhYCMyZ59WOp95I4DKDD aW2qkxkWjIXN1W8in9KXkPj+U6r1dkfEGOhmb2zttU/5nnPyCCTfYMfgk+bWnWuBs0M1 CN0Fvdwn96ifGMQIH//dlrY1GuMqhGizBiiIUoL38bgf6SnZuy44IeTlEi383iXKGKUl mc9KeGqk6ZIpyzqRD5DI6D+/bs+5ImmF+rWfLuGyYm1lvN04TnNk+TDmmDBuH8PtpLhK SkMA== X-Gm-Message-State: AGi0PuZVBLYb1PgJckCWfFmqB1BFRu3zHjArHt+4o3R1hHpe6vyBrbo/ m29L/wwOCqmCcfUcnFzUKx71QiNSMgU29uwylDg= X-Received: by 2002:a92:88d0:: with SMTP id m77mr4417557ilh.282.1586295927057; Tue, 07 Apr 2020 14:45:27 -0700 (PDT) MIME-Version: 1.0 References: <20200219171225.5547-1-idryomov@gmail.com> In-Reply-To: From: Ilya Dryomov Date: Tue, 7 Apr 2020 23:45:14 +0200 Message-ID: Subject: Re: [PATCH v2] vsprintf: don't obfuscate NULL and error pointers To: Petr Mladek Cc: Linux Kernel Mailing List , Linus Torvalds , Steven Rostedt , Randy Dunlap , Kees Cook , Sergey Senozhatsky , "Tobin C . Harding" , Rasmus Villemoes , Andy Shevchenko , Andy Shevchenko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 19, 2020 at 8:23 PM Ilya Dryomov wrote: > > On Wed, Feb 19, 2020 at 7:07 PM Ilya Dryomov wrote: > > > > On Wed, Feb 19, 2020 at 6:37 PM Andy Shevchenko > > wrote: > > > > > > On Wed, Feb 19, 2020 at 7:13 PM Ilya Dryomov wrote: > > > > > > > > I don't see what security concern is addressed by obfuscating NULL > > > > and IS_ERR() error pointers, printed with %p/%pK. Given the number > > > > of sites where %p is used (over 10000) and the fact that NULL pointers > > > > aren't uncommon, it probably wouldn't take long for an attacker to > > > > find the hash that corresponds to 0. Although harder, the same goes > > > > for most common error values, such as -1, -2, -11, -14, etc. > > > > > > > > The NULL part actually fixes a regression: NULL pointers weren't > > > > obfuscated until commit 3e5903eb9cff ("vsprintf: Prevent crash when > > > > dereferencing invalid pointers") which went into 5.2. I'm tacking > > > > the IS_ERR() part on here because error pointers won't leak kernel > > > > addresses and printing them as pointers shouldn't be any different > > > > from e.g. %d with PTR_ERR_OR_ZERO(). Obfuscating them just makes > > > > debugging based on existing pr_debug and friends excruciating. > > > > > > > > Note that the "always print 0's for %pK when kptr_restrict == 2" > > > > behaviour which goes way back is left as is. > > > > > > > > Example output with the patch applied: > > > > > > > > ptr error-ptr NULL > > > > %p: 0000000001f8cc5b fffffffffffffff2 0000000000000000 > > > > %pK, kptr = 0: 0000000001f8cc5b fffffffffffffff2 0000000000000000 > > > > %px: ffff888048c04020 fffffffffffffff2 0000000000000000 > > > > %pK, kptr = 1: ffff888048c04020 fffffffffffffff2 0000000000000000 > > > > %pK, kptr = 2: 0000000000000000 0000000000000000 0000000000000000 > > > > > > ... > > > > > > > +/* > > > > + * NULL pointers aren't hashed. > > > > + */ > > > > static void __init > > > > null_pointer(void) > > > > { > > > > - test_hashed("%p", NULL); > > > > + test(ZEROS "00000000", "%p", NULL); > > > > test(ZEROS "00000000", "%px", NULL); > > > > test("(null)", "%pE", NULL); > > > > } > > > > > > > > +/* > > > > + * Error pointers aren't hashed. > > > > + */ > > > > +static void __init > > > > +error_pointer(void) > > > > +{ > > > > + test(ONES "fffffff5", "%p", ERR_PTR(-EAGAIN)); > > > > + test(ONES "fffffff5", "%px", ERR_PTR(-EAGAIN)); > > > > > > > + test("(efault)", "%pE", ERR_PTR(-EAGAIN)); > > > > > > Hmm... Is capital E on purpose here? > > > > Yes. It shows that for %pE an error pointer is still invalid. > > %pe is tested separately, in errptr(), and the output would have > > been "-EAGAIN". > > > > > Maybe we may use something else ('%ph'?) for sake of deviation? > > > > If you look at the resulting file, you will see that null_pointer(), > > error_pointer() and invalid_pointer() exercise the same three variants: > > %p, %px and %pE. > > > > This is somewhat confusing, but there seems to be some disagreement > > between Pavel and Rasmus as to how the test suite should be structured > > and I didn't want to attempt to restructure anything in this patch. > > Sorry, I meant Petr of course. > > Rasmus, who had to deal with mips defining EDQUOT to 1133 by special > casing that in lib/errname.c, reminded me that error codes are a mess: > EAGAIN is different on alpha. Rather than picking another error code > that is the same on all architectures, let's just use explicit -11. > > error_pointer() should be: > > test(ONES "fffffff5", "%p", ERR_PTR(-11)); > test(ONES "fffffff5", "%px", ERR_PTR(-11)); > test("(efault)", "%pE", ERR_PTR(-11)); > > I'll wait for more feedback and respin (or perhaps this can be > fixed up while applying). Hi Petr, Bump, as I don't see this in linux-next or other public branches. The discussion was split between several threads, revolving around the vision for how lib/test_printf.c should be structured, but the fix itself wasn't disputed. Could you please pick it up for 5.7-rc1? If you want to restructure the test suite before adding any new test cases, v1 doesn't have them. Other than the test cases, the only difference between v1 and v2 is added reviews and acks. Thanks, Ilya