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=-1.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 8F085C43613 for ; Thu, 20 Jun 2019 13:54:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 61E912084A for ; Thu, 20 Jun 2019 13:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561038859; bh=ujco4toh4VcjlC1PwExMobr+TbEakBM2rfFRTVzVA9w=; h=Subject:From:To:Cc:Date:In-Reply-To:References:List-ID:From; b=Y29RvW7aTHAfW4tlnzZEPxnBOwL8+4D5EHYVE0BCe0RLAoEuG1AeNFq7IpRlR9Pb8 1K4TpOlXSYclGL8kx2WPWS2vvAJEPAPK0SCNhli7IwXWf6Gu4IgdUouwiMtNgaBV1D /ImZ5w80Jsj6Ro9E8xbsJ4Sk7fYVHlocvAXhuVX4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731553AbfFTNyS (ORCPT ); Thu, 20 Jun 2019 09:54:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:51436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726551AbfFTNyR (ORCPT ); Thu, 20 Jun 2019 09:54:17 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 149E920675; Thu, 20 Jun 2019 13:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561038856; bh=ujco4toh4VcjlC1PwExMobr+TbEakBM2rfFRTVzVA9w=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=DcVNrNiFpeuOwljp7LA2Gtb02dNaMIRCyt2onZkB+mR6mFkpcrSlYGpiTB9KervaC /H9aM9bFIH90qaIB4tLZYT5gsUm8dXfLXtqP0hiqbkQiyxN/OtVbv7oXBTxHX9fWFk qfMa7L8TI19+SYm/jjA1KH+05QZpKoxAhMLYBMng= Message-ID: Subject: Re: [PATCH v2 0/3] ceph: don't NULL terminate virtual xattr values From: Jeff Layton To: Geert Uytterhoeven Cc: Andy Shevchenko , Linux Kernel Mailing List , ceph-devel , Ilya Dryomov , Zheng Yan , sage@redhat.com, agruenba@redhat.com, Joe Perches , Petr Mladek , Steven Rostedt , Geert Uytterhoeven Date: Thu, 20 Jun 2019 09:54:13 -0400 In-Reply-To: References: <20190619164528.31958-1-jlayton@kernel.org> <20190620102410.GT9224@smile.fi.intel.com> <7c12abe8a7e6cd3cfe9129a1e74d9c788ff2f1a9.camel@kernel.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.2 (3.32.2-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-06-20 at 14:22 +0200, Geert Uytterhoeven wrote: > Hi Jeff, > > On Thu, Jun 20, 2019 at 1:41 PM Jeff Layton wrote: > > On Thu, 2019-06-20 at 13:24 +0300, Andy Shevchenko wrote: > > > On Wed, Jun 19, 2019 at 12:45:25PM -0400, Jeff Layton wrote: > > > > v2: drop bogus EXPORT_SYMBOL of static function > > > > > > > > The only real difference between this set and the one I sent originally > > > > is the removal of a spurious EXPORT_SYMBOL in the snprintf patch. > > > > > > > > I'm mostly sending this with a wider cc list in an effort to get a > > > > review from the maintainers of the printf code. Basically ceph needs a > > > > snprintf variant that does not NULL terminate in order to handle its > > > > virtual xattrs. > > > > > > > > Joe Perches had expressed some concerns about stack usage in vsnprintf > > > > with this, but I'm not sure I really understand the basis of that > > > > concern. If it is problematic, then I could use suggestions as to how > > > > best to fix that up. > > > > > > It might be problematic, since vsnprintf() can be called recursively. > > > > > > > So the concern is that we'd have extra call/ret activity in the stack? > > That seems like a lot of hand-wringing over very little, but ok if so. > > > > > > ----------------------------8<----------------------------- > > > > > > > > kcephfs has several "virtual" xattrs that return strings that are > > > > currently populated using snprintf(), which always NULL terminates the > > > > string. > > > > > > > > This leads to the string being truncated when we use a buffer length > > > > acquired by calling getxattr with a 0 size first. The last character > > > > of the string ends up being clobbered by the termination. > > > > > > So, then don't use snprintf() for this, simple memcpy() designed for that kind > > > of things. > > > > > > > memcpy from what? For many of these xattrs, we need to format integer > > data into strings. I could roll my own routine to do this formatting, > > but that's sort of what sprintf and its variants are for and I'd rather > > not reimplement all of it from scratch. > > snprintf() to a temporary buffer, and memcpy() to the final destination. > These are all fairly small buffers (most are single integer values), > so the overhead should be minimal, right? > Yeah. I was trying to avoid having to deal with a second buffer, but this is not a performance-critical codepath, so maybe that's the best option. > In fact the two largest strings are already formatted in a temporary > buffer, so there is no reason ceph_vxattrcb_layout() cannot just use > snprintf() now. > > Or perhaps this can use the existing seq_*() interface in some form? > Hmm. I'll have to think about that. > BTW, while at it, please get rid of the casts when calling snprintf(), and > use the correct format specifiers instead. > Sure, will do. Thanks for the suggestions so far (and from Andy too), -- Jeff Layton