Commit df36ec36 authored by Dean Luick's avatar Dean Luick Committed by Zeng Heng
Browse files

IB/hfi1: Restore allocated resources on failed copyout

stable inclusion
from stable-v4.19.273
commit 00d9e212b8a39e6ffcf31b9d2e503d2bf6009d45
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9R4LR
CVE: CVE-2023-52747

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=00d9e212b8a39e6ffcf31b9d2e503d2bf6009d45



----------------------------------------------------

[ Upstream commit 6601fc0d ]

Fix a resource leak if an error occurs.

Fixes: f404ca4c ("IB/hfi1: Refactor hfi_user_exp_rcv_setup() IOCTL")
Signed-off-by: default avatarDean Luick <dean.luick@cornelisnetworks.com>
Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Link: https://lore.kernel.org/r/167354736291.2132367.10894218740150168180.stgit@awfm-02.cornelisnetworks.com


Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarZeng Heng <zengheng4@huawei.com>
parent 53c51ceb
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1345,12 +1345,15 @@ static int user_exp_rcv_setup(struct hfi1_filedata *fd, unsigned long arg,
		addr = arg + offsetof(struct hfi1_tid_info, tidcnt);
		if (copy_to_user((void __user *)addr, &tinfo.tidcnt,
				 sizeof(tinfo.tidcnt)))
			return -EFAULT;
			ret = -EFAULT;

		addr = arg + offsetof(struct hfi1_tid_info, length);
		if (copy_to_user((void __user *)addr, &tinfo.length,
		if (!ret && copy_to_user((void __user *)addr, &tinfo.length,
				 sizeof(tinfo.length)))
			ret = -EFAULT;

		if (ret)
			hfi1_user_exp_rcv_invalid(fd, &tinfo);
	}

	return ret;