Unverified Commit 996007a5 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!14245 selinux: improve error checking in sel_write_load()

parents 8fbcff00 a48bd769
Loading
Loading
Loading
Loading
+17 −14
Original line number Diff line number Diff line
@@ -536,6 +536,16 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
	ssize_t length;
	void *data = NULL;

	/* no partial writes */
	if (*ppos)
		return -EINVAL;
	/* no empty policies */
	if (!count)
		return -EINVAL;

	if (count > 64 * 1024 * 1024)
		return -EFBIG;

	mutex_lock(&fsi->mutex);

	length = avc_has_perm(&selinux_state,
@@ -544,23 +554,15 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
	if (length)
		goto out;

	/* No partial writes. */
	length = -EINVAL;
	if (*ppos != 0)
		goto out;

	length = -EFBIG;
	if (count > 64 * 1024 * 1024)
		goto out;

	length = -ENOMEM;
	data = vmalloc(count);
	if (!data)
	if (!data) {
		length = -ENOMEM;
		goto out;

	}
	if (copy_from_user(data, buf, count) != 0) {
		length = -EFAULT;
	if (copy_from_user(data, buf, count) != 0)
		goto out;
	}

	length = security_load_policy(fsi->state, data, count);
	if (length) {
@@ -579,6 +581,7 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
		"auid=%u ses=%u lsm=selinux res=1",
		from_kuid(&init_user_ns, audit_get_loginuid(current)),
		audit_get_sessionid(current));

out:
	mutex_unlock(&fsi->mutex);
	vfree(data);