linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Luis Henriques <lhenriques@suse.com>,
	Jeff Layton <jlayton@kernel.org>,
	Ilya Dryomov <idryomov@gmail.com>,
	Sasha Levin <sashal@kernel.org>,
	ceph-devel@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 05/19] ceph: fix directories inode i_blkbits initialization
Date: Tue,  1 Oct 2019 12:44:51 -0400	[thread overview]
Message-ID: <20191001164505.16708-5-sashal@kernel.org> (raw)
In-Reply-To: <20191001164505.16708-1-sashal@kernel.org>

From: Luis Henriques <lhenriques@suse.com>

[ Upstream commit 750670341a24cb714e624e0fd7da30900ad93752 ]

When filling an inode with info from the MDS, i_blkbits is being
initialized using fl_stripe_unit, which contains the stripe unit in
bytes.  Unfortunately, this doesn't make sense for directories as they
have fl_stripe_unit set to '0'.  This means that i_blkbits will be set
to 0xff, causing an UBSAN undefined behaviour in i_blocksize():

  UBSAN: Undefined behaviour in ./include/linux/fs.h:731:12
  shift exponent 255 is too large for 32-bit type 'int'

Fix this by initializing i_blkbits to CEPH_BLOCK_SHIFT if fl_stripe_unit
is zero.

Signed-off-by: Luis Henriques <lhenriques@suse.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ceph/inode.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 339fdf6355df7..7fcddaaca8a5d 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -800,7 +800,12 @@ static int fill_inode(struct inode *inode, struct page *locked_page,
 	ci->i_version = le64_to_cpu(info->version);
 	inode->i_version++;
 	inode->i_rdev = le32_to_cpu(info->rdev);
-	inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
+	/* directories have fl_stripe_unit set to zero */
+	if (le32_to_cpu(info->layout.fl_stripe_unit))
+		inode->i_blkbits =
+			fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
+	else
+		inode->i_blkbits = CEPH_BLOCK_SHIFT;
 
 	if ((new_version || (new_issued & CEPH_CAP_AUTH_SHARED)) &&
 	    (issued & CEPH_CAP_AUTH_EXCL) == 0) {
-- 
2.20.1


  parent reply	other threads:[~2019-10-01 16:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-01 16:44 [PATCH AUTOSEL 4.9 01/19] ima: always return negative code for error Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 02/19] fs: nfs: Fix possible null-pointer dereferences in encode_attrs() Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 03/19] 9p: avoid attaching writeback_fid on mmap with type PRIVATE Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 04/19] xen/pci: reserve MCFG areas earlier Sasha Levin
2019-10-01 16:44 ` Sasha Levin [this message]
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 06/19] ceph: reconnect connection if session hang in opening state Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 07/19] drm/amdgpu: Check for valid number of registers to read Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 08/19] cdc_ncm: fix divide-by-zero caused by invalid wMaxPacketSize Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 09/19] usbnet: ignore endpoints with " Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 10/19] net/phy: fix DP83865 10 Mbps HDX loopback disable function Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 11/19] thermal: Fix use-after-free when unregistering thermal zone device Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 12/19] fuse: fix memleak in cuse_channel_open Sasha Levin
2019-10-01 16:44 ` [PATCH AUTOSEL 4.9 13/19] arcnet: provide a buffer big enough to actually receive packets Sasha Levin
2019-10-01 16:45 ` [PATCH AUTOSEL 4.9 14/19] ppp: Fix memory leak in ppp_write Sasha Levin
2019-10-01 16:45 ` [PATCH AUTOSEL 4.9 15/19] sched/core: Fix migration to invalid CPU in __set_cpus_allowed_ptr() Sasha Levin
2019-10-01 16:45 ` [PATCH AUTOSEL 4.9 16/19] kernel/elfcore.c: include proper prototypes Sasha Levin
2019-10-01 16:45 ` [PATCH AUTOSEL 4.9 17/19] macsec: drop skb sk before calling gro_cells_receive Sasha Levin
2019-10-01 16:45 ` [PATCH AUTOSEL 4.9 18/19] usbnet: sanity checking of packet sizes and device mtu Sasha Levin
2019-10-01 16:45 ` [PATCH AUTOSEL 4.9 19/19] sch_netem: fix a divide by zero in tabledist() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191001164505.16708-5-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=jlayton@kernel.org \
    --cc=lhenriques@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).