Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp986945ybi; Fri, 14 Jun 2019 06:46:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDWhGyyabElQfDm1IEJpI1KpJf53Jml6NvcAetLmE+OgbeeqsjGwqy4LUp6POaiF1kvt8E X-Received: by 2002:a17:90a:7f91:: with SMTP id m17mr11311934pjl.86.1560520017781; Fri, 14 Jun 2019 06:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560520017; cv=none; d=google.com; s=arc-20160816; b=pqxG9SKP36T3fe1hBTwdT0QCQHC2autRCH3pLX1NjAQiLPngwbkWhn4JtEGTHNbTf2 mVR+SlX9qTfPUOMboNwrFPHnosWiU+75NfbaEKkiyXwbc0lG8Rm1Ny5qe6eIilpdpr5l DrcvEYEjaJ1DTLPJL3lmtwFo+4Z2wlkeLbS4LCLLweLbVEGwLP0dyLMxC3HOfe6MlGpU xYgPOmtayAbuBbj0+kgDY78EArnqsTevxE5baSGKPgqzZJx9ReCtxTbZtQudQ0A/bQBM C5b5Rf4QJuFYcmOk3MrhbYYXofoIvnSwxLpBaKmTDow5DrM8NHlD9ugyeui3XO9nGd4S VnYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=813YyfF1GovRbJ84TJhHSuO886JtDXU6yk1kiEVWytw=; b=tMBaPMx05SiR4yCqiOsDd4V4qquhPIcUFYHMQEwkO8aSB0m8tdUOVXm3MUIgtMg8hc 4FaN+dtyAvm+35p6gj3ZffyNWESCcRsTQxpkVGrFew5aB4vRcB3OTizRigF9hf/oy5Dj +2c9t1MmgYa9rxGzY+YUIUiPRaxith48/fmii8kN1ERPhXBim18myYd9SDRuorbhurUA fodN+9Esqpx+jITJJRw3Mnlo7+uA6pe5QEeozIfLv1ckQN5SU6Fm6g8B6EdWk4iKz/RD +ohUd+FEzX88qw2c0mP/D9ZvkIeotBVe5pv5ffK92hegA7kc4xQ8fLntY/KnwRG7SuJt CqxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l2H8kA6n; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si2389535pjw.61.2019.06.14.06.46.39; Fri, 14 Jun 2019 06:46:57 -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; dkim=pass header.i=@kernel.org header.s=default header.b=l2H8kA6n; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728396AbfFNNq3 (ORCPT + 99 others); Fri, 14 Jun 2019 09:46:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:41928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728061AbfFNNq1 (ORCPT ); Fri, 14 Jun 2019 09:46:27 -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 750E32168B; Fri, 14 Jun 2019 13:46:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560519987; bh=Pk73/xkfvswS3oDbkwy/KBqHTKF7UicnSaCndmc/Fec=; h=From:To:Cc:Subject:Date:From; b=l2H8kA6nwkejbUj+mU7hs6Dczy+qaqNHwHugz/3YKhwgdT/6JhNh/7cZbLuTLd5HY XD06qWG0sMdQEo0UH4fVvDY5Sd/Lm74XGIzOFrJua3OY7t010vwpAyS+axTDhMWnrm 6rLTT7kIMrdh5FkjounPmS4VcLHxfsArvArssdDg= From: Jeff Layton To: linux-kernel@vger.kernel.org, ceph-devel@vger.kernel.org Cc: akpm@linux-foundation.org, idryomov@gmail.com, zyan@redhat.com, sage@redhat.com, agruenba@redhat.com Subject: [PATCH 0/3] ceph: don't NULL terminate virtual xattr values Date: Fri, 14 Jun 2019 09:46:22 -0400 Message-Id: <20190614134625.6870-1-jlayton@kernel.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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