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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 94DCDC47092 for ; Sun, 30 May 2021 15:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BC82611AC for ; Sun, 30 May 2021 15:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbhE3PVI (ORCPT ); Sun, 30 May 2021 11:21:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbhE3PVH (ORCPT ); Sun, 30 May 2021 11:21:07 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 389A4C061574; Sun, 30 May 2021 08:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=y3DXZLXagxiVtFwWPQ3/eHYfS2BTxh16gXAXVZkHbvs=; b=ERoCFxV5SBNYHz1mskauOJriQG y0EBj4Br/zzwvWrtLk3vX22nZllTohRJ5TQZXvvoR/DlZWEdD3+J+aWd0D3MjDgXqjeMomuoREo15 Cfme5ehFNPenJvMiyHyXZhqmVhuziWXecTBPN2yyAErWv0+ZAjvCLEpJ92Ql6y1m+BoQ6Laiocewj hDPS6WoBh9JirO2W57C45f6LVKRUSZVMBQx/E/OIb+lhnSF5lAShLs5xdPXkA101Cn4AzSahmxMsp NXTwIOgJlFR9nzMnOPnnJ3kTwfN5Ap8ZJoaS1yNCQw5RN7dpPBfESQiaB/yYHdk3cdZr0ikeOD0Kl eA1SFVtg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lnNCp-008Dun-I2; Sun, 30 May 2021 15:18:26 +0000 Date: Sun, 30 May 2021 16:18:23 +0100 From: Matthew Wilcox To: Rasmus Villemoes Cc: Justin He , Linus Torvalds , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Jonathan Corbet , Alexander Viro , Luca Coelho , Kalle Valo , "David S. Miller" , Jakub Kicinski , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Johannes Berg , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-wireless@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-s390@vger.kernel.org" Subject: Re: [PATCH RFCv2 2/3] lib/vsprintf.c: make %pD print full path for file Message-ID: References: <20210528113951.6225-1-justin.he@arm.com> <20210528113951.6225-3-justin.he@arm.com> <89fc3919-ca2c-50fd-35e1-33bf3a59b993@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <89fc3919-ca2c-50fd-35e1-33bf3a59b993@rasmusvillemoes.dk> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Fri, May 28, 2021 at 10:06:37PM +0200, Rasmus Villemoes wrote: > On 28/05/2021 16.22, Justin He wrote: > > > >> From: Matthew Wilcox > > >> How is it "safer"? You already have a buffer passed from the caller. > >> Are you saying that d_path_fast() might overrun a really small buffer > >> but won't overrun a 256 byte buffer? > > No, it won't overrun a 256 byte buf. When the full path size is larger than 256, the p->len is < 0 in prepend_name, and this overrun will be > > dectected in extract_string() with "-ENAMETOOLONG". > > > > Each printk contains 2 vsnprintf. vsnprintf() returns the required size after formatting the string.> > > 1. vprintk_store() will invoke 1st vsnprintf() will 8 bytes space to get the reserve_size. In this case, the _buf_ could be less than _end_ by design. > > 2. Then it invokes 2nd printk_sprint()->vscnprintf()->vsnprintf() to really fill the space. > > Please do not assume that printk is the only user of vsnprintf() or the > only one that would use a given %p extension. > > Also, is it clear that nothing can change underneath you in between two > calls to vsnprintf()? IOW, is it certain that the path will fit upon a > second call using the size returned from the first? No, but that's also true of %s. I think vprintk_store() is foolish to do it this way.