From patchwork Thu Jan 27 11:11:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12726572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1643C433F5 for ; Thu, 27 Jan 2022 11:11:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CE696B0071; Thu, 27 Jan 2022 06:11:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 32FB16B0072; Thu, 27 Jan 2022 06:11:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F6B86B0073; Thu, 27 Jan 2022 06:11:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0247.hostedemail.com [216.40.44.247]) by kanga.kvack.org (Postfix) with ESMTP id 09A156B0071 for ; Thu, 27 Jan 2022 06:11:06 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BDB948DF68 for ; Thu, 27 Jan 2022 11:11:05 +0000 (UTC) X-FDA: 79075800090.13.C54FEF7 Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120083.outbound.protection.outlook.com [40.107.12.83]) by imf27.hostedemail.com (Postfix) with ESMTP id 065BF4001F for ; Thu, 27 Jan 2022 11:11:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I42kGmnE+yS21c18UG8eltM7x0NDEvO+npq6iacmltWC3aV8RqZLg5DtCkSD/my/ksPKcO3U3pDBk2YyqhVL2vs1pOjTGFFpBG6mADTg/HrdEK4AidcUtf5XPaW+RwPfz7G/F4A8RL3b87jzUtaZCGsvw0dFnqsD2LmVq1wW8tV9Ko66D/gd2TBJC0arKme/DGJMPFR9VTOvS2580kUCYkD5ZSUlhRfH6aXXpb4SOI/nZ3ZpU343liLGG/qj5KEHganJs0CbjGr2AtynfwIzqDfgLpDmMmT5a0Cdir2pY7BfjJjVuDwIXrMv1lKK0qOQ87kc7hKH1gO8qXiygEf3Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fIgTZxqSZO1QNZwfuUqG001grn+BNYRNWoSYcZOdTF8=; b=bX7M1rpv8IqdN9283Xnn3xeXMZbXIZxltiDvUVOuujbkRX0k0wgfScGGwsBN3LXmiSs7ZO63tMmGRUnrCffvAsdjCpZ1oe1D1mjNpsVU9CMsqoiYpf5LI6vUl52VuEsvQdve93wIeJRKB3U7nxhICRRP1g987/LVZfplL88DlmgZ4fss0Sl7bm1p8SBDStjnANbMj+CWNzIdWlKvk1vXThyvQ2xMesVAEDM/GUiaHIixiSqVvaUU1a69GJXTA3ZV97CdjgX5YRzNz4Z28gl8KvVykS3mQfoeLMUQTO00hkNdc7j/u112ySwuv9Jdn56FgGxxAWk5Gbrs7o7AhfmTWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR0P264MB0442.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:12::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.13; Thu, 27 Jan 2022 11:11:02 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1%6]) with mapi id 15.20.4930.017; Thu, 27 Jan 2022 11:11:02 +0000 From: Christophe Leroy To: Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" Subject: [PATCH] vsprintf: Fix %pK with kptr_restrict == 0 Thread-Topic: [PATCH] vsprintf: Fix %pK with kptr_restrict == 0 Thread-Index: AQHYE26SrKWjcZwXqUqoxqk7jKGITg== Date: Thu, 27 Jan 2022 11:11:02 +0000 Message-ID: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 24b0b010-31e2-4189-ff89-08d9e185b49c x-ms-traffictypediagnostic: PR0P264MB0442:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: naXCe6Xod7T0SaI6x8uUQbxFZ+mHWuIEYHTnWcyknVLJqjQ9K7AEwf4FL6Svr7ti8xg0ppg+XkzLW+3AXNFljbcb/X5Bj3bsWJnL04MijsWAKD1Av3cTlX9I0wM/G+70GbVRibpanDPHOL6jrAQ8ierI9oeatOIIWlV8rs3XdzDjoiXYuRrUOQPuOFteCV9bi0O751mjUhlR7WbfQTAWNILZZlHq4jktpS+K0SE+gbM+Y9FaXYQS86m6EiQYIm1nzjIDcyd1UPSIHG6UUJipWh5zJmn7dg4jiO0GR4x5E2Je6A8GedncR/fOsUJMrZ5AtKxb+gyfg7vqDQVhAkl/88+6DsaCwC6hRc2AN96q7IIb0Kt8yDg2OugVDOoQ2dIM9w+qULDB7ZpsSbnbATr6/hfDUQecim+YI67KGL5y1O3rxkor3gbssV1UJuZz2BPj5ShfYwlWZqmOH9lF6CypzPcwC9fuBgT+hGKSPSmfaFnLO/p5QVL9v6oziMvBbK6uzhMBJf/15KfIThtxtKAt/1E4W7mIfqUe8DHxdlHzbTJkzSjrZs5rtng2EjUmH9WBggQQf5bHkcDAph1Sgf2Cjm8rNWKhDbfFyUFlh4kMJSszFhk+G0MhmFvb506/UiOSOxHXt3i2VuhzDNam4LyjzKIfqP45hnp5YkHDk0m4xSiop0R1joOcAj5FFdGeWrlL7pbCdMb/o3hmeWktiTUJkg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(26005)(8676002)(4326008)(86362001)(186003)(71200400001)(508600001)(110136005)(8936002)(66556008)(38070700005)(6512007)(6486002)(66446008)(76116006)(64756008)(54906003)(66476007)(91956017)(2906002)(83380400001)(66946007)(6506007)(5660300002)(2616005)(316002)(122000001)(44832011)(36756003)(38100700002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?dCt1Oags4DN1QSGjQu6Xnkm?= =?iso-8859-1?q?oz7fWtXZEXLPfI+S2oOKi/nib6CSzqGRdImsE93klO+Cx9+Ih2+z5Up4ssxJ?= =?iso-8859-1?q?ZKoCFI2DvDr0YczIUckCp+NMfiLI5px6MuSZixLv+rlfPdsmzPMzz3UF5pEu?= =?iso-8859-1?q?9DxXN76ijuEqDo/usxQarpJNVQeUn1ph/n4bKnm1paAg+PSlD86DDqaEMZ9y?= =?iso-8859-1?q?OXHO7f7i1Uw9eqT8L1rMdPmmBritXoOM6JWMM1dNB9hFgn7HCNSoXGDtXlZO?= =?iso-8859-1?q?bn84fZ4smD6w9CAq4yM66KrqFIYAoE1n8GM6sZvO6EK2JXhrlQTkCNth2H0S?= =?iso-8859-1?q?F/9mpDXxCemhxRTLV5z513m/S0w+9X3jPSMsWemO/EkB+0SetaZaP2Q1nAw8?= =?iso-8859-1?q?aq+fuRJwc4mSfkbcHmnWXm5s2PG6YspIqpYnxFVfBktSVeeAT6uoFDb0C8sg?= =?iso-8859-1?q?dZ/+RjEMM9hz+HjUD0E6SPZdCOGyOPW/QzKFzSvF8dIvvqWGrNTiK9GCc+k7?= =?iso-8859-1?q?XC5OGcJQtTrLB+2oLIzV6es1FTPe7K2KkCE+7V7Xp3+gQ/qFQoZ8REI02ew0?= =?iso-8859-1?q?4ZWan/Wk6QQPHpwX0Xd802xAunU6tmpmBeWhJdFaQhDmB1tKXLA4lxg198OG?= =?iso-8859-1?q?AfYQZhE62vYHnqq23G5IA3J6jCwUuhXK4yRoO6+4GFbJssTyT0wGd8SInfM+?= =?iso-8859-1?q?WUc337sgj7+wjzhlhRQPTywuyc6HPQibm7VAJEJw+06lCBErWWOafvjr7GFT?= =?iso-8859-1?q?qd0R991VlNU6wGeqBFMZT9N7BCOCDuZywfWHJnTdx889dZheqLzBa2W0w9Ll?= =?iso-8859-1?q?nGHzOp7tkFhwUsl4NzY3VRUTDU7hA0TPzB/Bbe7mbJApFMgkvvc95KfBhyLu?= =?iso-8859-1?q?pAPlJNcfmD+mWB6+aQ7VR3q8yKxo0NNappVnU9SA3cTZ1l5v0/to6JRyBje9?= =?iso-8859-1?q?f56bNoe2QpAg87dkfIVVQs4KXTAGWmkPYB8I0CsgID8I0fCre1i0TLFTADAF?= =?iso-8859-1?q?7QlkJy/o4nFNql8ddcRDHxGppPOWx92Al1yeLUpKV7YStvVt2Twjmdq616zs?= =?iso-8859-1?q?2jZLh+kXV7PWU5srmeU3p6XOlJyGPkFYPI//7xVr1uGkvjBCI7J9IytecGXa?= =?iso-8859-1?q?z2ULyQ3kghixHwamAIC9IBaUKIHon339qfsepAaLOiKiG9Hj7YLVhc8KIotQ?= =?iso-8859-1?q?lByXm0HVmD8iFDk4qpofG2ZYAFsMP+yy8hYiObhJesUOCrWkzLM6TrZpsW0u?= =?iso-8859-1?q?JZP6J9VrivzDYjc/28vZi0oJizJ61H8xiUCrgfuU2Ko0fH8HxGH/NbPzTOeE?= =?iso-8859-1?q?7SOV6xuvF+Avd51znLQChv8WKrniZWHvdZSJnvyw5PICe3vSf65FBnHzum05?= =?iso-8859-1?q?qj6BXpp3Kt0nUhid4XG7OTONiOrnlc8ghU2L1NXHCmIOfBuobS2cWkKGem0U?= =?iso-8859-1?q?afgmPsKpO6PePZvs+AAfhR21w8VY533Wbt++fb66iAK204aYjXvN1VHpuLD3?= =?iso-8859-1?q?HDpjlOdzVCbil/UDCGkb0GXhATwoOePVVQw1TnNNBKNnMUkBXRoaAbALug3N?= =?iso-8859-1?q?XhzbIEGp78Gd2xcP9tGYHd3l3yrJQN3XDhOW2DusV/1sLr7Jr2EcFeJRegwH?= =?iso-8859-1?q?qwsrtKDeeEc94DsN007xOrc8bBavgu4nc53adKOK0JWNW9baY7a0DXHsgqIP?= =?iso-8859-1?q?1bJFy62IxRO71U+ovg8IZVFebn1yRmw5KAXl4n62iyrAXY6fNyOnwcDwoFtw?= =?iso-8859-1?q?GpAc=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 24b0b010-31e2-4189-ff89-08d9e185b49c X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jan 2022 11:11:02.6411 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: rfMlezRQzE+dAL1lIZ0Sa0cmey0dvbZ9nBBXYm76W9AqrYuxFdhEPe9wy5d58OBYNPjZ8OpwYmV7XHdv3BX55jhhxorNeVzVlhhBCe2l37E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR0P264MB0442 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 065BF4001F X-Stat-Signature: o96i4cqxe4wwuudbizeypkfykqko75r1 Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.83 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none X-Rspam-User: nil X-HE-Tag: 1643281864-108588 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: Although kptr_restrict is set to 0 and the kernel is booted with no_hash_pointers parameter, the content of /proc/vmallocinfo is lacking the real addresses. / # cat /proc/vmallocinfo 0x(ptrval)-0x(ptrval) 8192 load_module+0xc0c/0x2c0c pages=1 vmalloc 0x(ptrval)-0x(ptrval) 12288 start_kernel+0x4e0/0x690 pages=2 vmalloc 0x(ptrval)-0x(ptrval) 12288 start_kernel+0x4e0/0x690 pages=2 vmalloc 0x(ptrval)-0x(ptrval) 8192 _mpic_map_mmio.constprop.0+0x20/0x44 phys=0x80041000 ioremap 0x(ptrval)-0x(ptrval) 12288 _mpic_map_mmio.constprop.0+0x20/0x44 phys=0x80041000 ioremap ... According to the documentation for /proc/sys/kernel/, %pK is equivalent to %p when kptr_restrict is set to 0. Fixes: 1ac2f9789c4b ("vsprintf: Consistent %pK handling for kptr_restrict == 0") Signed-off-by: Christophe Leroy --- lib/vsprintf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3b8129dd374c..9c60d6e1a0d6 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -848,6 +848,10 @@ static char *ptr_to_id(char *buf, char *end, const void *ptr, return pointer_string(buf, end, (const void *)hashval, spec); } +/* Disable pointer hashing if requested */ +bool no_hash_pointers __ro_after_init; +EXPORT_SYMBOL_GPL(no_hash_pointers); + int kptr_restrict __read_mostly; static noinline_for_stack @@ -857,6 +861,8 @@ char *restricted_pointer(char *buf, char *end, const void *ptr, switch (kptr_restrict) { case 0: /* Handle as %p, hash and do _not_ leak addresses. */ + if (unlikely(no_hash_pointers)) + break; return ptr_to_id(buf, end, ptr, spec); case 1: { const struct cred *cred; @@ -2223,10 +2229,6 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode, return widen_string(buf, buf - buf_start, end, spec); } -/* Disable pointer hashing if requested */ -bool no_hash_pointers __ro_after_init; -EXPORT_SYMBOL_GPL(no_hash_pointers); - int __init no_hash_pointers_enable(char *str) { if (no_hash_pointers)