From patchwork Mon Nov 26 22:39:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 10699243 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 52A3E109C for ; Mon, 26 Nov 2018 22:39:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FABB2A747 for ; Mon, 26 Nov 2018 22:39:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 215F72A74A; Mon, 26 Nov 2018 22:39:33 +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 BC95F2A747 for ; Mon, 26 Nov 2018 22:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727076AbeK0JfK (ORCPT ); Tue, 27 Nov 2018 04:35:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45928 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727066AbeK0JfK (ORCPT ); Tue, 27 Nov 2018 04:35:10 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E010D1390C for ; Mon, 26 Nov 2018 22:39:31 +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 A1D6919936; Mon, 26 Nov 2018 22:39:31 +0000 (UTC) To: linux-xfs Cc: Zorro Lang From: Eric Sandeen Subject: [PATCH] mkfs.xfs: null-terminate symlinks created via protofile Message-ID: Date: Mon, 26 Nov 2018 16:39:30 -0600 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 Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 26 Nov 2018 22:39:31 +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 Now that we have a symlink verifier which checks that in-memory symlink names are null-terminated, be sure we do that when we create them via the mkfs protofile. We only want to null-terminate inline data if it's a symlink; we only ever /call/ newfile() with "dolocal" for symlinks, so rename that function argument for clarity. Zorro found this by running xfs/019 on an s390x machine, it failed with: Metadata corruption detected at 0x101214a, inode 0x89 data fork Signed-off-by: Eric Sandeen Reported-by: Zorro Lang diff --git a/mkfs/proto.c b/mkfs/proto.c index 1cd5436..d76c80d 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -15,7 +15,7 @@ static char *getstr(char **pp); static void fail(char *msg, int i); static struct xfs_trans * getres(struct xfs_mount *mp, uint blocks); static void rsvfile(xfs_mount_t *mp, xfs_inode_t *ip, long long len); -static int newfile(xfs_trans_t *tp, xfs_inode_t *ip, int dolocal, int logit, +static int newfile(xfs_trans_t *tp, xfs_inode_t *ip, int symlink, int logit, char *buf, int len); static char *newregfile(char **pp, int *len); static void rtinit(xfs_mount_t *mp); @@ -220,7 +220,7 @@ static int newfile( xfs_trans_t *tp, xfs_inode_t *ip, - int dolocal, + int symlink, int logit, char *buf, int len) @@ -236,7 +236,9 @@ newfile( flags = 0; mp = ip->i_mount; - if (dolocal && len <= XFS_IFORK_DSIZE(ip)) { + if (symlink && len <= XFS_IFORK_DSIZE(ip)) { + /* Copy the name's trailing NULL as well */ + len += 1; libxfs_idata_realloc(ip, len, XFS_DATA_FORK); if (buf) memmove(ip->i_df.if_u1.if_data, buf, len);