Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp688241pxj; Fri, 28 May 2021 13:07:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgOHM58fbjc98f9vMU2ZHvkkDAsEQ+BFf0bhf00DhL8eUYkIL4W90yr9F6+a8zsWU5GH6A X-Received: by 2002:a5e:cb45:: with SMTP id h5mr8122129iok.207.1622232431231; Fri, 28 May 2021 13:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622232431; cv=none; d=google.com; s=arc-20160816; b=XAe6cSrynthZ31mthGaQJbDfCY60QYwqSch7BL8kH205KEssxOnKYwiGeBDmctVm4A XdU47Mh3aLIq3E71NWoIYcYH+WWd6cULAueqi7wfPJHl2UYjsi9YbFmkstNhBpwMpVoa slP3U/a2kGLYuDJE0vkq6gZQL1etr19rnIGQx9NdQwrAQQhxZUeH0ArD/LNchf2n/LlU 9WJR1joe5a/opA/K6LpNkFbqjzjGeJK5MaaRIU/kXWgsYiF5/FcuZinAZ4OFeWBF918W oARzq2p0B0YL8yrUvAVESkdMa+fJqN7nMosFyEmNiNsxB6+bXDvPq3QfJ0IjDGJhIzdZ pzNA== 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=SOmtzfnBo6NCPJmKRQ2bxbkBgbCrNqNnPAbwGffPcTs=; b=Q7f6P0/QnIAWGA8F2PbOl6TYgWJYtOe9FdJ33A44mUsUn7eV7M7CVjOOCYSfwx/2c7 5c2SFOO4clkMeqdCYy6/3yH2f2vxnB3c7/W1baH7YLvYlL19HapYB9pndnXLyO7UKHvu Wl3S8wCA1EtNK6I2hHQ4lu+IT6Zx1YYQQqGo8+Sn2hTtRzdK+fg6/p7x8dpkGRuIRsq/ QZIjCUrjbHjy/Cv5NmCuf0FHaFwtrAvZAXU69lbFjftWH3HPJ523vFnVwe8WWgPvOGQD YrG8z4oe3TeADT2Ok9IaF2xaiGLrzzL8Dr4xZR5DdAILHh5fePOlfrwVYYD9QuiUuZXC RCzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=L006ZDgf; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 s13si7924175ilu.55.2021.05.28.13.06.45; Fri, 28 May 2021 13:07:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=L006ZDgf; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229594AbhE1UIR (ORCPT + 99 others); Fri, 28 May 2021 16:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbhE1UIQ (ORCPT ); Fri, 28 May 2021 16:08:16 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A72DC061760 for ; Fri, 28 May 2021 13:06:41 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id e17so7021562lfb.2 for ; Fri, 28 May 2021 13:06:41 -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=SOmtzfnBo6NCPJmKRQ2bxbkBgbCrNqNnPAbwGffPcTs=; b=L006ZDgfzIz2uNo0e1HI0KncA6d5iUevfwGopHwj6KZ0AzwLFmI7P+KSXJTBenAtKt YvhygMCnEymm4R7ZuS6YSodjYjIrJh7LSsEhj+yn2mu+dh45d5tZjF54ls96OiZjrKl0 /pLSn9bC8pY1aZrCrWbmH+zopo0dZdc4fx0t0= 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=SOmtzfnBo6NCPJmKRQ2bxbkBgbCrNqNnPAbwGffPcTs=; b=NbHiXzpnqp1ozQIKBLIBwgkXXvyJ3e5F9Z0DO146i7ikGYS8kUvHv6qNgZZCPJtBPb fO1R7Ltxj7cqjXWBW6lQkyXbrfSrJ3Njjwkcph+xh+lOC5fjUP+1ocWMeTmErgz3KARx vVWx/r8JP8UVVI7cqX0qYrQoITeKbwNSJh27Q/WeCiwPzFIFGLyKxAja+6MnDBaWcCrq dbC/a7ybHL4hRyCCUziMovvNsA+25Pu65wXBES02mRtAjVHYOS28U0r7n5qKsO/DpbwK 6dmxactMTV1Ad9fA1V7uhlDJhzAeFS+3GOFpvHG0cT9opIPU04xAnitdMwe+C8eiGBzj CyCw== X-Gm-Message-State: AOAM533DURneLcE3kplMadrIjbGzQh0fLam6r7xMZcGDHEje37DqNZqF 3BGkYnErFrnzZThgdvwiY3R8PQ== X-Received: by 2002:a05:6512:28e:: with SMTP id j14mr6669923lfp.360.1622232399648; Fri, 28 May 2021 13:06:39 -0700 (PDT) Received: from [172.17.20.105] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id k8sm600385lfg.190.2021.05.28.13.06.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 May 2021 13:06:39 -0700 (PDT) Subject: Re: [PATCH RFCv2 2/3] lib/vsprintf.c: make %pD print full path for file To: Justin He , Matthew Wilcox Cc: 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" References: <20210528113951.6225-1-justin.he@arm.com> <20210528113951.6225-3-justin.he@arm.com> From: Rasmus Villemoes Message-ID: <89fc3919-ca2c-50fd-35e1-33bf3a59b993@rasmusvillemoes.dk> Date: Fri, 28 May 2021 22:06:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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? Rasmus