Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp45262pxf; Wed, 24 Mar 2021 20:28:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqum5Cc427QwZnCCGxJJanzzw7XvOptMbOJtYnnPgCuwkDe2O1XJMirq9fEUpBkA84X5gk X-Received: by 2002:a17:906:9bdb:: with SMTP id de27mr7176408ejc.459.1616642916286; Wed, 24 Mar 2021 20:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616642916; cv=none; d=google.com; s=arc-20160816; b=d8PNdXhv6wUbhL+vxY71bMrQbOI8PNCO9O9Xft/VAUss2ohd56v0PWiCi3y9PyWLgI jjyesSuGNI5Dq2s4sh6auGXlT7Uwt6YYkpUNyJFGNpELv8UXbclJNq9yRV3LhXjNvHy+ 9NxbKOsUtkQADNJiY2YNw859lT/c2fmfxP29ku43uiYllZlXsgkJRQTYVRjSGDWyqLtd bvD3TM7vbbBW3yHDlB/Is4Z4551aBQ8ikNpdOva5N53bPT9cgOeQ13vFh+v68HFdN4+h PyDUYnfHzV8zBY02d8vf3dq1A8BJ0ZXJyQ72s7ucGK03DDzPW3sS99LYScEpdXCRoj6x NtdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=qg+uRN1UVz59bXG8ixTxLJaA4rnDyKRg9P1HWdnjvz8=; b=MRQtC9MCfOwP3BxXzWQRHnLjxIDXqIWrvjx0gf8SL10CarvvCsm/Hz3cYI+CTtb+/M 8hjUuRSxBFFMgx5U5bFMOAb679eNQa4F1ht9mNiis1SSliKF7SSpdWD1f1mlhyTxxTMc 1lZJYfQ7ST9JhJWBIRKhk+dJN391uJdkfMCRFDY5/yjKzQB3tXhS5BAhGIkfvvS8qD+h BwjbpCHKA1NgSqi6WKI7is7MaK7LripnCuoYzlfi0+SAc43FzQmyVet5qWQT0tAPS85B syHls9Kqd2MVY43KdTle2/W9Q1QfnQdlhpDOIZ17BeXC0YjDcIRQLeWk7SupKnwWG9wl hpIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=imlEBMen; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z9si3519265ejr.490.2021.03.24.20.28.14; Wed, 24 Mar 2021 20:28:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=imlEBMen; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233578AbhCXV2Q (ORCPT + 99 others); Wed, 24 Mar 2021 17:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233716AbhCXV1p (ORCPT ); Wed, 24 Mar 2021 17:27:45 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6C3CC06174A for ; Wed, 24 Mar 2021 14:27:44 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id e7so66210edu.10 for ; Wed, 24 Mar 2021 14:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qg+uRN1UVz59bXG8ixTxLJaA4rnDyKRg9P1HWdnjvz8=; b=imlEBMenzGIyx7jNh1TSp0GkwYJn3xsLEdndnorUwCqqRGh1tYECPHFLjjETSoZyuv s96amsaGRhRnwtS2FAyBn0CCiLkOmGJPHTqkW2S1/MhhXfVUa1m4oWnzdtypFMBSnVx9 DAVVDh7KdgasdUXwd6zMs+zngrQXyGJaVsvi4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qg+uRN1UVz59bXG8ixTxLJaA4rnDyKRg9P1HWdnjvz8=; b=Ta5/0vG8zanAZ52y78RX1119zPddRc2kxB2Yw3q7iWPtrwRdoNtD/C47nteHgW/Bwj ZOnH1VgpAHP75T45Jb89ujDwZVmmfWDnU/4ovCTFrKPCOVNnQ/tM0Gg41F4T5DYqeU4o JzJop/aT1MIPB/IS/cSWltNQo9s4ieQwgBl7imSnEQju8mKLxv34QX1DTa2DlC+CQP0j QA+xe6eTWPX0ie3Dg1Q8YaFSgxZ02+2Ow4tkekMxEVTSc6Uwryxx2qdQen4LsCwx7VM2 oJUzUUJzPwYh8pmLAqIeAFe/3pSScokgqld7YBZhhxuv4flBNfVarmzDBVN4Ooqh+hfH Kg9Q== X-Gm-Message-State: AOAM531VbQ8j26bYy0i+bxiYPQSj14n1+9N4RwPBqY5/oi7dPN+/Zu1B P71Js4DQm6nYn5WV9u3UdHB0prLh2hPUexYN X-Received: by 2002:a05:6402:51cd:: with SMTP id r13mr5693993edd.116.1616621263348; Wed, 24 Mar 2021 14:27:43 -0700 (PDT) Received: from [192.168.1.149] ([80.208.71.248]) by smtp.gmail.com with ESMTPSA id s20sm1717716edu.93.2021.03.24.14.27.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Mar 2021 14:27:42 -0700 (PDT) Subject: Re: [RFC patch] vsprintf: Allow %pe to print non PTR_ERR %pe uses as decimal To: Joe Perches , Arnd Bergmann , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko Cc: Philipp Zabel , David Airlie , Daniel Vetter , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Marco Felsch , Laurent Pinchart , Liu Ying , dri-devel , Linux ARM , Linux Kernel Mailing List References: <20210324121832.3714570-1-arnd@kernel.org> <810d36184b9fa2880d3ba7738a8f182e27f5107b.camel@perches.com> <3252fd83141aa9e0e6001acee1dd98e87c676b9a.camel@perches.com> <9feab1e8-4dee-6b79-03f7-7b9f0cb24f6e@rasmusvillemoes.dk> From: Rasmus Villemoes Message-ID: <3d66137e-7842-2764-456f-7cc9e54a6d2e@rasmusvillemoes.dk> Date: Wed, 24 Mar 2021 22:27:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/03/2021 20.24, Joe Perches wrote: > On Wed, 2021-03-24 at 18:33 +0100, Rasmus Villemoes wrote: >> On 24/03/2021 18.20, Joe Perches wrote: >> >>> >>> Maybe it's better to output non PTR_ERR %pe uses as decimal so this >>> sort of code would work. >> >> No, because that would leak the pointer value when somebody has >> accidentally passed a real kernel pointer to %pe. > > I think it's not really an issue. > > _All_ code that uses %p extensions need inspection anyway. There are now a bunch of sanity checks in place that catch e.g. an ERR_PTR passed to an extension that would derefence the pointer; enforcing that only ERR_PTRs are passed to %pe (or falling back to %p) is another of those safeguards. > It's already possible to intentionally 'leak' the ptr value > by using %pe, -ptr so I think that's not really an issue. > Huh, what? I assume -ptr is shorthand for (void*)-(unsigned long)ptr. How would that leak the value if ptr is an ordinary kernel pointer? That's not an ERR_PTR unless (unsigned long)ptr is < 4095 or so. If you want to print the pointer value just do %px. No need for silly games. What I'm talking about is preventing _un_intentionally leaking a valid kernel pointer value. So no, a non-ERR_PTR passed to %pe is not going to be printed as-is, not in decimal or hexadecimal or roman numerals. >> If the code wants a cute -EFOO string explaining what's wrong, what >> about "%pe", ERR_PTR(mux < 0 : mux : -ERANGE)? Or two separate error >> messages >> >> if (mux < 0) >>   ... >> else if (mux >= ARRAY_SIZE()) >>   ... > > Multiple tests, more unnecessary code, multiple format strings, etc... Agreed, I'm not really advocating for the latter; the former suggestion is IMO a pretty concise way of providing useful information in dmesg. Rasmus