Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1179898ybi; Fri, 14 Jun 2019 09:57:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5Hemf0U6BvW3XczGZ+gqQUgsqSQWQEpvownsPdhMCWBkk51wyYm33XCx6/d0qIR+NM+Bp X-Received: by 2002:a17:902:30a3:: with SMTP id v32mr95270681plb.6.1560531434501; Fri, 14 Jun 2019 09:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560531434; cv=none; d=google.com; s=arc-20160816; b=jIzgUIRKwvfD8WiPVscnlaSAAaTHLQuECQWgJbY/lA4tRO+lG0PGQmkd4zj5DjFuh0 ZLY8kRZgYaW17RctwggNtVRRQXWveVpUHTqVZBPtg0pFU4gmiv3XV7hebYYHBfTCpwM8 f1txARJghwTzJJy7DhyOBTAYgjIKzz9ew92dYbi885sDS3kB2RKQn4b0Wq5bOXlGtzrt NmFHGlsHyPRCa5FVChoOR+57ki32L9HpWUR6vG9PgCRQNI+0RbMX4gOPFIEn8Y/Imw9H w2lxgMfDlQMNop1iZC5XCdRCm/m2mt7MJQxHi+Pn59yjEq5xH/0BeBJjoxWlNLQsoKyQ jE9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=cNzgw8zU6lYxY9116+VTCavjD+4v/EZJ92kV6MCy3Hw=; b=cfERW5vbWggpH+Y4AiCQ1zCcmU4K7IP4vLK6W+Gf3d1ovJe8fr3uQ+oFIarHLLVBY1 EAAIXpxgTJFP8cd1vfRR6Kmpr7BteXsHI5UdNntvpAYgMw70QjoBMVjPosN3mUvxzYVi DZuHoB9g4L31sFibo8YnCk7Bkg31CgZ7RKhsAmnGYZYkLzl3rMMWYH8iQ6aww24DhZ52 Q+bs/EWNCjw+klOS7ZyHswJmf8S6r/bNFdH9JQ16TRcgCeHnMXttjwr2O0gWPIs1xdYO KCRfIHD9WY+FW+doRnpcDdQ4nXuhSuvTDtWDaj00SNuOrSdrOx8rYDuOhMAxnnGCtiH/ KaSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si2947216pgv.67.2019.06.14.09.56.59; Fri, 14 Jun 2019 09:57:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726283AbfFNQ4q (ORCPT + 99 others); Fri, 14 Jun 2019 12:56:46 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:41780 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfFNQ4q (ORCPT ); Fri, 14 Jun 2019 12:56:46 -0400 Received: by mail-ot1-f66.google.com with SMTP id 107so3268138otj.8 for ; Fri, 14 Jun 2019 09:56:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cNzgw8zU6lYxY9116+VTCavjD+4v/EZJ92kV6MCy3Hw=; b=s/5eC/OJh3nz2/Aj9YrYRVi6F6dv1odBaUTahO++IAPH2Tdb4trqt0Dg4kHvUrNMd1 4STt5E105y7IcCO/v6O7LkRc7hjTeKeMUhb0XriPB5lIJGuCzRGPkS3FSBipt0YSCP+J wMHm7eyrFPrG2kOWeAql8GiFGD2MQ5BgNagzd5lXP3fMNoeM02Utfsiu0X4gT7bbqytK 4WEqGORuuZxcEkxDXv8WwFnWmWETxWMKNqRMpejYLjog/+yQ+OtiAmGEC4u7bZg2hZUJ U5kXRNNnOTIF1/gbGmiuN/5NzG1W16e3f5Yiklk4xWFy/NKArraHBpZIpyqUZJPNsGrr AbxA== X-Gm-Message-State: APjAAAUqZgvucR+S99Ecdpac6dHrAy9Mi04ljAD2XPdsB0EdZ8aM3xI2 YM5LGUAQDD0sFLFp9eRBveyyNWDFNIEXtNNF1uFxsQ== X-Received: by 2002:a9d:704f:: with SMTP id x15mr17973354otj.297.1560531405363; Fri, 14 Jun 2019 09:56:45 -0700 (PDT) MIME-Version: 1.0 References: <20190614134625.6870-1-jlayton@kernel.org> In-Reply-To: <20190614134625.6870-1-jlayton@kernel.org> From: Andreas Gruenbacher Date: Fri, 14 Jun 2019 18:56:34 +0200 Message-ID: Subject: Re: [PATCH 0/3] ceph: don't NULL terminate virtual xattr values To: Jeff Layton Cc: LKML , Ceph Development , Andrew Morton , Ilya Dryomov , "Yan, Zheng" , Sage Weil Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 14 Jun 2019 at 15:46, Jeff Layton wrote: > 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. > > The convention with xattrs is to not store the termination with string > data, given that we have the length. This is how setfattr/getfattr > operate. > > This patch makes ceph's virtual xattrs not include NULL termination > when formatting their values. In order to handle this, a new > snprintf_noterm function is added, and ceph is changed over to use > this to populate the xattr value buffer. Finally, we fix ceph to > return -ERANGE properly when the string didn't fit in the buffer. This looks reasonable from an xattr point of view. Thanks, Andreas > Jeff Layton (3): > lib/vsprintf: add snprintf_noterm > ceph: don't NULL terminate virtual xattr strings > ceph: return -ERANGE if virtual xattr value didn't fit in buffer > > fs/ceph/xattr.c | 49 +++++++------- > include/linux/kernel.h | 2 + > lib/vsprintf.c | 145 ++++++++++++++++++++++++++++------------- > 3 files changed, 130 insertions(+), 66 deletions(-) > > -- > 2.21.0 >