From patchwork Tue Dec 11 19:02:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10724477 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 28D0E13BF for ; Tue, 11 Dec 2018 19:03:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17B722B682 for ; Tue, 11 Dec 2018 19:03:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08CCD2B6A4; Tue, 11 Dec 2018 19:03:05 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 9E8C52B682 for ; Tue, 11 Dec 2018 19:03:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726329AbeLKTDD (ORCPT ); Tue, 11 Dec 2018 14:03:03 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:33822 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbeLKTDD (ORCPT ); Tue, 11 Dec 2018 14:03:03 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBBIs9Ep085765; Tue, 11 Dec 2018 19:02:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=QPsIUCvXaytwGoWfwz5pSFp0zH7Uwg8Fquwt1WkGRRo=; b=cSDG+bIxOIJK7EbKPVKsoDb9XdaFNnMETDfy5wW8ez9ocv80UNdQJUNbH5XXeeqn3rOn eGfu8z7ksWcyDEmArD+Elbxlc5hw3Us6xhpTT8faUdTRa48I6gRT+PN8hg4U88nplRag RivHHGGHw6ZibDyv7gZ7Eu84SvOWRAf8e0OGI+azjO8AmNP+u3Gq0yWKql1svG3K7mcC k/9SkN3rx0dtreh/VjJDOfyqXER29c52fTU1BFfCeI+UbAixtx15QDNfYu2JOKh/Iq/O QuhtnGP3RBOHwHvNkQ2s+ZgMe/iXWW5yi98fA03l9MsI2dIfsiWLOcXOcycrPARcHWuV BQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2p85cu5syv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Dec 2018 19:02:58 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wBBJ2wKR018848 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Dec 2018 19:02:58 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wBBJ2wes021839; Tue, 11 Dec 2018 19:02:58 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 Dec 2018 11:02:57 -0800 Date: Tue, 11 Dec 2018 11:02:56 -0800 From: "Darrick J. Wong" To: Eric Sandeen Cc: Eric Sandeen , linux-xfs , Zorro Lang Subject: [PATCH] mkfs: fix symlink target if_bytes computation for protofile Message-ID: <20181211190256.GV24487@magnolia> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9103 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=980 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812110168 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 From: Darrick J. Wong When creating a local format symlink, we expect the target buffer in the data fork to have enough space to contain the null, but we also expect if_bytes to reflect the length of the target /not/ including the null. If we don't adjust if_bytes down by one byte, we can run off into uninitialized memory. Fix this, which should clean up the spurious xfs/019 failures for good. Signed-off-by: Darrick J. Wong Signed-off-by: Eric Sandeen Reviewed-by: Darrick J. Wong --- mkfs/proto.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mkfs/proto.c b/mkfs/proto.c index fc07de5f..dc0225bd 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -238,10 +238,18 @@ newfile( flags = 0; mp = ip->i_mount; if (symlink && len <= XFS_IFORK_DSIZE(ip)) { - /* Copy the name's trailing NULL as well */ + /* + * Local format symbolic link targets are supposed to be NULL + * terminated in memory. This means that if_data must be at + * least one byte longer than the target string's length so + * that there's enough space to hold the null. However, we + * still expect if_bytes to be strlen(target), which does _not_ + * include the null. + */ libxfs_idata_realloc(ip, len + 1, XFS_DATA_FORK); if (buf) memmove(ip->i_df.if_u1.if_data, buf, len + 1); + ip->i_df.if_bytes = len; ip->i_d.di_size = len; ip->i_df.if_flags &= ~XFS_IFEXTENTS; ip->i_df.if_flags |= XFS_IFINLINE;