Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6012716ybc; Wed, 27 Nov 2019 13:22:58 -0800 (PST) X-Google-Smtp-Source: APXvYqwVr8Hl0HGwz44iV2XrPfPac/dtB2kRXAtQQ1+TZKzdKwgwt7ynBIHMBkHlCyoCsBKlRAaX X-Received: by 2002:aa7:c141:: with SMTP id r1mr4445682edp.126.1574889778134; Wed, 27 Nov 2019 13:22:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889778; cv=none; d=google.com; s=arc-20160816; b=awSXlIv/IJmU3ATqxoiAujTdPHzYyvwASGarjppTQMsFsZ/4/PxubEysSXW1Ox7+t0 DWQt3La+D8tzKxfLs1K5+PsgV79h7Z82MRspdcX8B9jIkYj8TwA4gVLG/7eOqFJNkpQ2 h0yPqTRUP7PTowoPQPkNWSpZbWGoNuFU042hL5dLp6l7A316+F59pDHGr1ORqWpjb5My RQxXD5QgV6IPRy1pFYwc5wIBSYg2nwpFcm8/vb9E4UwsTUaNYQdj7m1stZNq648ZCHZ+ dh0iu0wzwD18h2NuS5YbBfd+kXYEg6mSYOGFEWqUgacaYMlyHv9Mcu+n09L1OBmxuuSG QpZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I8/U0cvbQ538+hEWUB3GnkU3KjKNc27++oCMTXqob7Y=; b=QilSa8TLceyUr+1cc4I+KWzBg22BFlypQJ5y/22S2CfyAeEuWP7meC/TfnDmFndlla dCrxa4cnv/jUjDIKrdBpRFv4K2jSbIApzRzJHaI2yKkXh2/2gCruYZCDY8SQtSMDBfPG VQQ9v6slvwxdzENXnPRNXIzeyYRHgLDnYhu5RHG/tIWZvSMy3E6gdz91ZiX9xPjRKrtG gxBWA/3mC3NwPcNsKLYS/lGNATi/feLahaGnCem6VtvID8lqjkcW0QMnB18zy7J4FkWF jBHdjem9TVbwxsanznsoujsBc1tNoSSUSuSBxU/4lYDntUnLEuULy1owwcXtltKf2uZi Aqvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AlSjnA+p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c29si12402836ede.50.2019.11.27.13.22.34; Wed, 27 Nov 2019 13:22:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AlSjnA+p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732856AbfK0VJW (ORCPT + 99 others); Wed, 27 Nov 2019 16:09:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:35874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732863AbfK0VJP (ORCPT ); Wed, 27 Nov 2019 16:09:15 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C09121556; Wed, 27 Nov 2019 21:09:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888954; bh=BOiowEuy+RlWqcjqjvrERK6atbQLQnXcNLNSpSWSa24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AlSjnA+pUMyOlCAZvh6cRzwdcXnWl0ByQz1kWM9aEjVcBTWwHF8gOzFTmqlZnnMg5 2/JchH64rLT5ac3oo/m7/jYIVKoTov+RMz7emhNY+oespa4ka+q0yzEdMzOlilKKYA xkMddpfG7HbUlDEqpcTH24OlF2GNjs8BGZq4T5Bo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joseph Qi , Thomas Voegtle , Changwei Ge , Jia-Ju Bai , Mark Fasheh , Joel Becker , Junxiao Bi , Gang He , Jun Piao , Andrew Morton , Linus Torvalds Subject: [PATCH 5.3 27/95] Revert "fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()" Date: Wed, 27 Nov 2019 21:31:44 +0100 Message-Id: <20191127202854.186425693@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127202845.651587549@linuxfoundation.org> References: <20191127202845.651587549@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joseph Qi commit 94b07b6f9e2e996afff7395de6b35f34f4cb10bf upstream. This reverts commit 56e94ea132bb5c2c1d0b60a6aeb34dcb7d71a53d. Commit 56e94ea132bb ("fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()") introduces a regression that fail to create directory with mount option user_xattr and acl. Actually the reported NULL pointer dereference case can be correctly handled by loc->xl_ops->xlo_add_entry(), so revert it. Link: http://lkml.kernel.org/r/1573624916-83825-1-git-send-email-joseph.qi@linux.alibaba.com Fixes: 56e94ea132bb ("fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()") Signed-off-by: Joseph Qi Reported-by: Thomas Voegtle Acked-by: Changwei Ge Cc: Jia-Ju Bai Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Gang He Cc: Jun Piao Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/xattr.c | 56 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -1490,6 +1490,18 @@ static int ocfs2_xa_check_space(struct o return loc->xl_ops->xlo_check_space(loc, xi); } +static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash) +{ + loc->xl_ops->xlo_add_entry(loc, name_hash); + loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash); + /* + * We can't leave the new entry's xe_name_offset at zero or + * add_namevalue() will go nuts. We set it to the size of our + * storage so that it can never be less than any other entry. + */ + loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size); +} + static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc, struct ocfs2_xattr_info *xi) { @@ -2121,31 +2133,29 @@ static int ocfs2_xa_prepare_entry(struct if (rc) goto out; - if (!loc->xl_entry) { - rc = -EINVAL; - goto out; - } - - if (ocfs2_xa_can_reuse_entry(loc, xi)) { - orig_value_size = loc->xl_entry->xe_value_size; - rc = ocfs2_xa_reuse_entry(loc, xi, ctxt); - if (rc) - goto out; - goto alloc_value; - } + if (loc->xl_entry) { + if (ocfs2_xa_can_reuse_entry(loc, xi)) { + orig_value_size = loc->xl_entry->xe_value_size; + rc = ocfs2_xa_reuse_entry(loc, xi, ctxt); + if (rc) + goto out; + goto alloc_value; + } - if (!ocfs2_xattr_is_local(loc->xl_entry)) { - orig_clusters = ocfs2_xa_value_clusters(loc); - rc = ocfs2_xa_value_truncate(loc, 0, ctxt); - if (rc) { - mlog_errno(rc); - ocfs2_xa_cleanup_value_truncate(loc, - "overwriting", - orig_clusters); - goto out; + if (!ocfs2_xattr_is_local(loc->xl_entry)) { + orig_clusters = ocfs2_xa_value_clusters(loc); + rc = ocfs2_xa_value_truncate(loc, 0, ctxt); + if (rc) { + mlog_errno(rc); + ocfs2_xa_cleanup_value_truncate(loc, + "overwriting", + orig_clusters); + goto out; + } } - } - ocfs2_xa_wipe_namevalue(loc); + ocfs2_xa_wipe_namevalue(loc); + } else + ocfs2_xa_add_entry(loc, name_hash); /* * If we get here, we have a blank entry. Fill it. We grow our