From patchwork Tue Sep 25 03:00:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 10613275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1EEB6CB for ; Tue, 25 Sep 2018 03:00:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AC9629A87 for ; Tue, 25 Sep 2018 03:00:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F43A29A8E; Tue, 25 Sep 2018 03:00:45 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 1EF0B29A87 for ; Tue, 25 Sep 2018 03:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727659AbeIYJGE (ORCPT ); Tue, 25 Sep 2018 05:06:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32912 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727615AbeIYJGE (ORCPT ); Tue, 25 Sep 2018 05:06:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7687330842D0; Tue, 25 Sep 2018 03:00:44 +0000 (UTC) Received: from [IPv6:::1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4D1A19C9A; Tue, 25 Sep 2018 03:00:39 +0000 (UTC) Subject: [PATCH 2/2 V3] xfs: verify size-vs-format for symlinks & dirs To: Eric Sandeen , linux-xfs References: From: Eric Sandeen Cc: "Xu, Wen" Message-ID: <1e55b111-eae4-b0cf-0221-c96eb3f17b77@redhat.com> Date: Mon, 24 Sep 2018 22:00:39 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 25 Sep 2018 03:00:44 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Today, xfs_ifork_verify_data() will simply skip verification if the inode claims to be in non-local format. However, nothing catches the case where the size for the format is too small to be non-local. xfs_repair tests for this mismatch in process_check_inode_sizes(), so do the same in this verifier. Reported-by: Xu, Wen Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=200925 Signed-off-by: Eric Sandeen Reviewed-by: Brian Foster --- V2: restructure code & tests per Dave's suggestion on the V1 patch. V3: rewrite dave's comments per brian's suggestions diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index f9acf1d436f6..d1a58e7a872f 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -704,12 +704,33 @@ xfs_ifork_verify_data( struct xfs_inode *ip, struct xfs_ifork_ops *ops) { - /* Non-local data fork, we're done. */ - if (ip->i_d.di_format != XFS_DINODE_FMT_LOCAL) + struct xfs_mount *mp = ip->i_mount; + int mode = VFS_I(ip)->i_mode; + + /* + * Verify non-local format forks have a valid size. Symlinks must have + * outgrown the data fork size. The same goes for non-local dirs, but + * dirs grow at dirblock granularity. Perform a slightly stronger check + * and require the dir is at least one dirblock in size. + */ + if (ip->i_d.di_format != XFS_DINODE_FMT_LOCAL) { + switch (mode & S_IFMT) { + case S_IFDIR: + if (ip->i_d.di_size < mp->m_dir_geo->blksize) + return __this_address; + break; + case S_IFLNK: + if (ip->i_d.di_size <= XFS_IFORK_DSIZE(ip)) + return __this_address; + break; + default: + break; + } return NULL; + } /* Check the inline data fork if there is one. */ - switch (VFS_I(ip)->i_mode & S_IFMT) { + switch (mode & S_IFMT) { case S_IFDIR: return ops->verify_dir(ip); case S_IFLNK: