From patchwork Wed Jun 21 15:46:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 9802223 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B0149600C5 for ; Wed, 21 Jun 2017 16:23:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77DF9285BA for ; Wed, 21 Jun 2017 16:23:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7690C28645; Wed, 21 Jun 2017 16:23:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4B8C285BA for ; Wed, 21 Jun 2017 16:23:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752807AbdFUQXt (ORCPT ); Wed, 21 Jun 2017 12:23:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:53450 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751143AbdFUQXs (ORCPT ); Wed, 21 Jun 2017 12:23:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 682CFAC03; Wed, 21 Jun 2017 15:47:31 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 95680DA8D0; Wed, 21 Jun 2017 17:46:25 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: suy.fnst@cn.fujitsu.com, David Sterba Subject: [PATCH] btrfs: fix validation of XATTR_ITEM dir items Date: Wed, 21 Jun 2017 17:46:24 +0200 Message-Id: <20170621154624.28365-1-dsterba@suse.com> X-Mailer: git-send-email 2.13.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The XATTR_ITEM is a type of a directory item so we use the common validator helper. We have to adjust the limits because of potential data_len (ie. the xattr value), which is otherwise 0 for other directory items. Signed-off-by: David Sterba --- fs/btrfs/dir-item.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index 2b00dd746118..a48d496e63e4 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -498,6 +498,7 @@ bool btrfs_is_name_len_valid(struct extent_buffer *leaf, int slot, { struct btrfs_fs_info *fs_info = leaf->fs_info; struct btrfs_key key; + struct btrfs_dir_item *di; u32 read_start; u32 read_end; u32 item_start; @@ -515,8 +516,17 @@ bool btrfs_is_name_len_valid(struct extent_buffer *leaf, int slot, btrfs_item_key_to_cpu(leaf, &key, slot); switch (key.type) { - case BTRFS_DIR_ITEM_KEY: case BTRFS_XATTR_ITEM_KEY: + /* + * XATTR_ITEM could contain data so the item_end would not + * match read_end as for other item types. Artificially lower + * the upper bound so we check just name_len. We have to trust + * the data_len value here, but if it's too big the validation + * fails so it's safer than increasing read_end. + */ + di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); + item_end -= btrfs_dir_data_len(leaf, di); + case BTRFS_DIR_ITEM_KEY: case BTRFS_DIR_INDEX_KEY: size = sizeof(struct btrfs_dir_item); break;