[RHEL7,COMMIT] ms/ovl: Fix dereferencing possible ERR_PTR()

Submitted by Konstantin Khorenko on June 16, 2020, 10:47 a.m.


Message ID 202006161047.05GAl5qf030602@finist-ce7.sw.ru
State New
Series "ms/fs/proc/proc_sysctl.c: fix potential page fault while unregistering sysctl table"
Headers show

Commit Message

Konstantin Khorenko June 16, 2020, 10:47 a.m.
The commit is pushed to "branch-rh7-3.10.0-1127.10.1.vz7.162.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.10.1.vz7.162.3
commit 0fe2adea81ea2f2835abd51bab7616eb52236f97
Author: Ding Xiang <dingxiang@cmss.chinamobile.com>
Date:   Mon Sep 9 16:29:56 2019 +0800

    ms/ovl: Fix dereferencing possible ERR_PTR()
    if ovl_encode_real_fh() fails, no memory was allocated
    and the error in the error-valued pointer should be returned.
    Fixes: 9b6faee07470 ("ovl: check ERR_PTR() return value from ovl_encode_fh()")
    Signed-off-by: Ding Xiang <dingxiang@cmss.chinamobile.com>
    Cc: <stable@vger.kernel.org> # v4.16+
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
    Found by vvs@ using smatch on RHEL7.9 beta kernel:
    smatch: fs/overlayfs/export.c:249 ovl_d_to_fh() error: 'fh'
    dereferencing possible ERR_PTR()
    (cherry picked from commit 97f024b9171e74c4443bbe8a8dce31b917f97ac5)
    Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
 fs/overlayfs/export.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c
index 9a5ccbb08bf38..03acd05ba6427 100644
--- a/fs/overlayfs/export.c
+++ b/fs/overlayfs/export.c
@@ -230,9 +230,8 @@  static int ovl_d_to_fh(struct dentry *dentry, char *buf, int buflen)
 	/* Encode an upper or lower file handle */
 	fh = ovl_encode_real_fh(enc_lower ? ovl_dentry_lower(dentry) :
 				ovl_dentry_upper(dentry), !enc_lower);
-	err = PTR_ERR(fh);
 	if (IS_ERR(fh))
-		goto fail;
+		return PTR_ERR(fh);
 	err = -EOVERFLOW;
 	if (fh->len > buflen)