From patchwork Wed Jan 11 08:24:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9509467 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 7234F60231 for ; Wed, 11 Jan 2017 08:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FE8A285E5 for ; Wed, 11 Jan 2017 08:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54A32285EE; Wed, 11 Jan 2017 08:24:35 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 C0E81285E5 for ; Wed, 11 Jan 2017 08:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936324AbdAKIYe (ORCPT ); Wed, 11 Jan 2017 03:24:34 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34049 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933862AbdAKIYd (ORCPT ); Wed, 11 Jan 2017 03:24:33 -0500 Received: by mail-wm0-f68.google.com with SMTP id c85so35007685wmi.1 for ; Wed, 11 Jan 2017 00:24:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GSGNd07b0nsXUSLQULDobzM0EyuOPyQ2j1HS6o6D5Fo=; b=CejuoT1SQZZB63mhMmsOmZpOydGUl9rlx6smcsYi6F8cNKMx9sGAmXZmZBFCYvH8rf Y88o9TqLG8ixVc6BQCoMy6Q/rYSg34lB53kQJg+acFdVvDV0tuhdUu0Qc+EQTFiaNzvJ pP8bh1wHIjaZ+3p6BoIdvYfpdvnMoq/4xfLXmkgyrRBPYjTDwo0wAZvkeh04ZHT0Lhe7 aarrx9D2gjCa4SKDza64tLBk+71fYx/pM+pnrbUaa4jKo0WpQRLXBY74Xi3Mn0h5R2Ti 50BQl8QSl9TOYFof2Y/1mHrBIP9JeQioLuWgp2wZ45AtRwmwh0l8F0d/9vb9N72qcdDG AHMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GSGNd07b0nsXUSLQULDobzM0EyuOPyQ2j1HS6o6D5Fo=; b=TeYNPnx7VCJpl8EBRFCQLkGfZAHxR8z0UnQqZWQxg9Ud+s3S9IlVc/7J5Ki9XAY2Wv k4U5aq0fW+o7OH92WDscaMJ/xWXKz50h4W6fPbMs5OIXMjg2rDnxNPVHcoEOcENIX5Se R/j5d7eQ9OF+/Lu3xa1N7GIZId0ospHLqqc5H8BVuvKnms7McKBQxgAhny5udlA8GtJV Xrpi/FFBFSurYpRPCUpCKRHMIvCaVSmIRTAQIbi6AsfnRJ9UlqRJbB2lFKazgLEykp9F TQ3W8Al5WUJkPDDsy4W+ELkUCAWr+p+Cs/gIhZ3O/KrQtPMGSKTa18aHH8Qz+QqZBj7b DgtQ== X-Gm-Message-State: AIkVDXJMx71HJHe5MuJ1bcNdfVSqIasKnsW6xNc4gxUouHQKGCtFJj2JzEpSduAS2OVZAw== X-Received: by 10.28.41.5 with SMTP id p5mr4486356wmp.38.1484123071956; Wed, 11 Jan 2017 00:24:31 -0800 (PST) Received: from amir-VirtualBox.ctera.local (bzq-82-81-193-202.cablep.bezeqint.net. [82.81.193.202]) by smtp.gmail.com with ESMTPSA id l187sm7704670wml.6.2017.01.11.00.24.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jan 2017 00:24:31 -0800 (PST) From: Amir Goldstein To: "Darrick J . Wong" Cc: Brian Foster , Christoph Hellwig , linux-xfs@vger.kernel.org Subject: [PATCH v8 2/6] xfs: sanity check directory inode di_size Date: Wed, 11 Jan 2017 10:24:06 +0200 Message-Id: <1484123050-11064-3-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484123050-11064-1-git-send-email-amir73il@gmail.com> References: <1484123050-11064-1-git-send-email-amir73il@gmail.com> 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 This changes fixes an assertion hit when fuzzing on-disk i_mode values. The easy case to fix is when changing an empty file i_mode to S_IFDIR. In this case, xfs_dinode_verify() detects an illegal zero size for directory and fails to load the inode structure from disk. For the case of non empty file whose i_mode is changed to S_IFDIR, the ASSERT() statement in xfs_dir2_isblock() is replaced with return -EFSCORRUPTED, to avoid interacting with corrupted jusk also when XFS_DEBUG is disabled. Suggested-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Amir Goldstein --- fs/xfs/libxfs/xfs_dir2.c | 3 ++- fs/xfs/libxfs/xfs_inode_buf.c | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index c58d72c..4f7913f 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -631,7 +631,8 @@ xfs_dir2_isblock( if ((rval = xfs_bmap_last_offset(args->dp, &last, XFS_DATA_FORK))) return rval; rval = XFS_FSB_TO_B(args->dp->i_mount, last) == args->geo->blksize; - ASSERT(rval == 0 || args->dp->i_d.di_size == args->geo->blksize); + if (rval != 0 && args->dp->i_d.di_size != args->geo->blksize) + return -EFSCORRUPTED; *vp = rval; return 0; } diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index dd483e2..0091ac3 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -386,6 +386,7 @@ xfs_dinode_verify( xfs_ino_t ino, struct xfs_dinode *dip) { + uint16_t mode; uint16_t flags; uint64_t flags2; @@ -396,8 +397,10 @@ xfs_dinode_verify( if (be64_to_cpu(dip->di_size) & (1ULL << 63)) return false; - /* No zero-length symlinks. */ - if (S_ISLNK(be16_to_cpu(dip->di_mode)) && dip->di_size == 0) + mode = be16_to_cpu(dip->di_mode); + + /* No zero-length symlinks/dirs. */ + if ((S_ISLNK(mode) || S_ISDIR(mode)) && dip->di_size == 0) return false; /* only version 3 or greater inodes are extensively verified here */