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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 AE7D8ECE587 for ; Tue, 1 Oct 2019 16:45:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C2B221A4C for ; Tue, 1 Oct 2019 16:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569948344; bh=VBpfkg9+vEMeWQ1VwqaiwwHBY3ZYF105rVStb5Nnl4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=guLUP1XAsVqud8EP3uTXqwAPsj9+YYCKj/a08dFbtvi7qLGeg1ZOaSEHnvuWGoSb5 FBPaLujsXgjdy17ltS3cwhE+Vwzn/EruqIb4/d4Y5PSnOgEeW2H6GusLAC4a8LgW0K ocDkG2W6LAJLXiR36MldgAw3T0nk/9onSYTFSH9A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390380AbfJAQpn (ORCPT ); Tue, 1 Oct 2019 12:45:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:58228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390356AbfJAQpj (ORCPT ); Tue, 1 Oct 2019 12:45:39 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6151521A4A; Tue, 1 Oct 2019 16:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569948339; bh=VBpfkg9+vEMeWQ1VwqaiwwHBY3ZYF105rVStb5Nnl4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ki+J01fiPJxVXyRLH3pZv6vLyWCnFkKv0YGV+KDIstIjir35gwhEQzh5Jvhfq32BK mYTwNCtiMwws0w0pZNqbt4kxTd+wA0x3TBUfJsSj0I2/iYoDX/ODK+HHhjXgKzlds+ N9f69IK0bqZdV3VZuJcZ0VQ27g8Qyjt9qgZUuP5U= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Luis Henriques , Jeff Layton , Ilya Dryomov , Sasha Levin , ceph-devel@vger.kernel.org Subject: [PATCH AUTOSEL 4.4 05/15] ceph: fix directories inode i_blkbits initialization Date: Tue, 1 Oct 2019 12:45:23 -0400 Message-Id: <20191001164533.16915-5-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191001164533.16915-1-sashal@kernel.org> References: <20191001164533.16915-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luis Henriques [ 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 Reviewed-by: Jeff Layton Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- 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 a663b676d5661..2ad3f4ab4dcfa 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -725,7 +725,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