Exemple #1
0
int aa_move_mount(struct aa_label *label, const struct path *path,
		  const char *orig_name)
{
	struct aa_profile *profile;
	char *buffer = NULL, *old_buffer = NULL;
	struct path old_path;
	int error;

	AA_BUG(!label);
	AA_BUG(!path);

	if (!orig_name || !*orig_name)
		return -EINVAL;

	error = kern_path(orig_name, LOOKUP_FOLLOW, &old_path);
	if (error)
		return error;

	get_buffers(buffer, old_buffer);
	error = fn_for_each_confined(label, profile,
			match_mnt(profile, path, buffer, &old_path, old_buffer,
				  NULL, MS_MOVE, NULL, false));
	put_buffers(buffer, old_buffer);
	path_put(&old_path);

	return error;
}
Exemple #2
0
int aa_bind_mount(struct aa_label *label, const struct path *path,
		  const char *dev_name, unsigned long flags)
{
	struct aa_profile *profile;
	char *buffer = NULL, *old_buffer = NULL;
	struct path old_path;
	int error;

	AA_BUG(!label);
	AA_BUG(!path);

	if (!dev_name || !*dev_name)
		return -EINVAL;

	flags &= MS_REC | MS_BIND;

	error = kern_path(dev_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
	if (error)
		return error;

	get_buffers(buffer, old_buffer);
	error = fn_for_each_confined(label, profile,
			match_mnt(profile, path, buffer, &old_path, old_buffer,
				  NULL, flags, NULL, false));
	put_buffers(buffer, old_buffer);
	path_put(&old_path);

	return error;
}
Exemple #3
0
status_t
multi_audio_control(void* cookie, uint32 op, void* arg, size_t len)
{
	switch(op) {
		case B_MULTI_GET_DESCRIPTION:			return get_description(cookie, arg);
		case B_MULTI_GET_EVENT_INFO:			return B_ERROR;
		case B_MULTI_SET_EVENT_INFO:			return B_ERROR;
		case B_MULTI_GET_EVENT:					return B_ERROR;
		case B_MULTI_GET_ENABLED_CHANNELS:		return get_enabled_channels(cookie, arg);
		case B_MULTI_SET_ENABLED_CHANNELS:		return B_OK;
		case B_MULTI_GET_GLOBAL_FORMAT:			return get_global_format(cookie, arg);
		case B_MULTI_SET_GLOBAL_FORMAT:			return set_global_format(cookie, arg);
		case B_MULTI_GET_CHANNEL_FORMATS:		return B_ERROR;
		case B_MULTI_SET_CHANNEL_FORMATS:		return B_ERROR;
		case B_MULTI_GET_MIX:					return B_ERROR;
		case B_MULTI_SET_MIX:					return B_ERROR;
		case B_MULTI_LIST_MIX_CHANNELS:			return list_mix_channels(cookie, arg);
		case B_MULTI_LIST_MIX_CONTROLS:			return list_mix_controls(cookie, arg);
		case B_MULTI_LIST_MIX_CONNECTIONS:		return list_mix_connections(cookie, arg);
		case B_MULTI_GET_BUFFERS:				return get_buffers(cookie, arg);
		case B_MULTI_SET_BUFFERS:				return B_ERROR;
		case B_MULTI_SET_START_TIME:			return B_ERROR;
		case B_MULTI_BUFFER_EXCHANGE:			return buffer_exchange(cookie, arg);
		case B_MULTI_BUFFER_FORCE_STOP:			return buffer_force_stop(cookie);
	}

	dprintf("null_audio: %s - unknown op\n" , __func__);
	return B_BAD_VALUE;
}
Exemple #4
0
int aa_new_mount(struct aa_label *label, const char *dev_name,
		 const struct path *path, const char *type, unsigned long flags,
		 void *data)
{
	struct aa_profile *profile;
	char *buffer = NULL, *dev_buffer = NULL;
	bool binary = true;
	int error;
	int requires_dev = 0;
	struct path tmp_path, *dev_path = NULL;

	AA_BUG(!label);
	AA_BUG(!path);

	if (type) {
		struct file_system_type *fstype;

		fstype = get_fs_type(type);
		if (!fstype)
			return -ENODEV;
		binary = fstype->fs_flags & FS_BINARY_MOUNTDATA;
		requires_dev = fstype->fs_flags & FS_REQUIRES_DEV;
		put_filesystem(fstype);

		if (requires_dev) {
			if (!dev_name || !*dev_name)
				return -ENOENT;

			error = kern_path(dev_name, LOOKUP_FOLLOW, &tmp_path);
			if (error)
				return error;
			dev_path = &tmp_path;
		}
	}

	get_buffers(buffer, dev_buffer);
	if (dev_path) {
		error = fn_for_each_confined(label, profile,
			match_mnt(profile, path, buffer, dev_path, dev_buffer,
				  type, flags, data, binary));
	} else {
		error = fn_for_each_confined(label, profile,
			match_mnt_path_str(profile, path, buffer, dev_name,
					   type, flags, data, binary, NULL));
	}
	put_buffers(buffer, dev_buffer);
	if (dev_path)
		path_put(dev_path);

	return error;
}
Exemple #5
0
int aa_remount(struct aa_label *label, const struct path *path,
	       unsigned long flags, void *data)
{
	struct aa_profile *profile;
	char *buffer = NULL;
	bool binary;
	int error;

	AA_BUG(!label);
	AA_BUG(!path);

	binary = path->dentry->d_sb->s_type->fs_flags & FS_BINARY_MOUNTDATA;

	get_buffers(buffer);
	error = fn_for_each_confined(label, profile,
			match_mnt(profile, path, buffer, NULL, NULL, NULL,
				  flags, data, binary));
	put_buffers(buffer);

	return error;
}
Exemple #6
0
int aa_mount_change_type(struct aa_label *label, const struct path *path,
			 unsigned long flags)
{
	struct aa_profile *profile;
	char *buffer = NULL;
	int error;

	AA_BUG(!label);
	AA_BUG(!path);

	/* These are the flags allowed by do_change_type() */
	flags &= (MS_REC | MS_SILENT | MS_SHARED | MS_PRIVATE | MS_SLAVE |
		  MS_UNBINDABLE);

	get_buffers(buffer);
	error = fn_for_each_confined(label, profile,
			match_mnt(profile, path, buffer, NULL, NULL, NULL,
				  flags, NULL, false));
	put_buffers(buffer);

	return error;
}
Exemple #7
0
int PluginArray::run_plugins()
{
// Length to write after process_loop
	int64_t write_length;

	done = 0;     // for when done
	error = 0;
	if(plugin_server->realtime)
	{
		int64_t len;
		MainProgressBar *progress;
		char string[BCTEXTLEN], string2[BCTEXTLEN];

		sprintf(string, _("%s..."), plugin_server->title);
		progress = mwindow->mainprogress->start_progress(string, end - start);

		for(int current_position = start; 
			current_position < end && !done && !error;
			current_position += len)
		{
			len = buffer_size;
			if(current_position + len > end) len = end - current_position;

// Process in plugin.  This pulls data from the modules
			get_buffers();
			for(int i = 0; i < total; i++)
			{
				process_realtime(i, current_position, len);
			}

// Write to file
			error = write_buffers(len);
			done = progress->update(current_position - start + len);
		}

		progress->get_time(string2);
		progress->stop_progress();
		delete progress;

		sprintf(string, _("%s took %s"), plugin_server->title, string2);
		mwindow->gui->lock_window();
		mwindow->gui->show_message(string2);
		mwindow->gui->unlock_window();
	}
	else
	{
// Run main loop once for multichannel plugins.
// Run multiple times for single channel plugins.
// Each write to the file must contain all the channels
		while(!done && !error)
		{
			for(int i = 0; i < total; i++)
			{
				write_length = 0;
				done += process_loop(i, write_length);
			}


			if(write_length)
				error = write_buffers(write_length);
		}
	}

	return error;
}
Exemple #8
0
static status_t
multi_audio_control_generic(cookie_type* cookie, uint32 op, void* arg, size_t len)
{
	status_t status;
	switch (op) {
		case B_MULTI_GET_DESCRIPTION:
		{
			multi_description description;
			multi_channel_info channels[16];
			multi_channel_info* originalChannels;

			if (user_memcpy(&description, arg, sizeof(multi_description))
					!= B_OK)
				return B_BAD_ADDRESS;

			originalChannels = description.channels;
			description.channels = channels;
			if (description.request_channel_count > 16)
				description.request_channel_count = 16;

			status = get_description(cookie, &description);
			if (status != B_OK)
				return status;

			description.channels = originalChannels;
			if (user_memcpy(arg, &description, sizeof(multi_description))
					!= B_OK)
				return B_BAD_ADDRESS;
			return user_memcpy(originalChannels, channels,
				sizeof(multi_channel_info) * description.request_channel_count);
		}

		case B_MULTI_GET_ENABLED_CHANNELS:
		{
			multi_channel_enable* data = (multi_channel_enable*)arg;
			multi_channel_enable enable;
			uint32 enable_bits;
			uchar* orig_enable_bits;

			if (user_memcpy(&enable, data, sizeof(enable)) != B_OK
				|| !IS_USER_ADDRESS(enable.enable_bits)) {
				return B_BAD_ADDRESS;
			}

			orig_enable_bits = enable.enable_bits;
			enable.enable_bits = (uchar*)&enable_bits;
			status = get_enabled_channels(cookie, &enable);
			if (status != B_OK)
				return status;

			enable.enable_bits = orig_enable_bits;
			if (user_memcpy(enable.enable_bits, &enable_bits,
					sizeof(enable_bits)) < B_OK
				|| user_memcpy(arg, &enable, sizeof(multi_channel_enable)) < B_OK) {
				return B_BAD_ADDRESS;
			}

			return B_OK;
		}
		case B_MULTI_SET_ENABLED_CHANNELS:
			return B_OK;

		case B_MULTI_GET_GLOBAL_FORMAT:
		{
			multi_format_info info;
			if (user_memcpy(&info, arg, sizeof(multi_format_info)) != B_OK)
				return B_BAD_ADDRESS;

			status = get_global_format(cookie, &info);
			if (status != B_OK)
				return B_OK;
			return user_memcpy(arg, &info, sizeof(multi_format_info));
		}
		case B_MULTI_SET_GLOBAL_FORMAT:
		{
			multi_format_info info;
			if (user_memcpy(&info, arg, sizeof(multi_format_info)) != B_OK)
				return B_BAD_ADDRESS;

			status = set_global_format(cookie, &info);
			if (status != B_OK)
				return B_OK;
			return user_memcpy(arg, &info, sizeof(multi_format_info));
		}
		case B_MULTI_LIST_MIX_CHANNELS:
			return list_mix_channels(cookie, (multi_mix_channel_info*)arg);
		case B_MULTI_LIST_MIX_CONTROLS:
		{
			multi_mix_control_info info;
			multi_mix_control* original_controls;
			size_t allocSize;
			multi_mix_control *controls;

			if (user_memcpy(&info, arg, sizeof(multi_mix_control_info)) != B_OK)
				return B_BAD_ADDRESS;

			original_controls = info.controls;
			allocSize = sizeof(multi_mix_control) * info.control_count;
			controls = (multi_mix_control *)malloc(allocSize);
			if (controls == NULL)
				return B_NO_MEMORY;

			if (!IS_USER_ADDRESS(info.controls)
				|| user_memcpy(controls, info.controls, allocSize) < B_OK) {
				free(controls);
				return B_BAD_ADDRESS;
			}
			info.controls = controls;

			status = list_mix_controls(cookie, &info);
			if (status != B_OK) {
				free(controls);
				return status;
			}

			info.controls = original_controls;
			status = user_memcpy(info.controls, controls, allocSize);
			if (status == B_OK)
				status = user_memcpy(arg, &info, sizeof(multi_mix_control_info));
			if (status != B_OK)
				status = B_BAD_ADDRESS;
			free(controls);
			return status;
		}
		case B_MULTI_LIST_MIX_CONNECTIONS:
			return list_mix_connections(cookie,
				(multi_mix_connection_info*)arg);
		case B_MULTI_GET_MIX:
		{
			multi_mix_value_info info;
			multi_mix_value* original_values;
			size_t allocSize;
			multi_mix_value *values;

			if (user_memcpy(&info, arg, sizeof(multi_mix_value_info)) != B_OK)
				return B_BAD_ADDRESS;

			original_values = info.values;
			allocSize = sizeof(multi_mix_value) * info.item_count;
			values = (multi_mix_value *)malloc(allocSize);
			if (values == NULL)
				return B_NO_MEMORY;

			if (!IS_USER_ADDRESS(info.values)
				|| user_memcpy(values, info.values, allocSize) < B_OK) {
				free(values);
				return B_BAD_ADDRESS;
			}
			info.values = values;

			status = get_mix(cookie, &info);
			if (status != B_OK) {
				free(values);
				return status;
			}

			info.values = original_values;
			status = user_memcpy(info.values, values, allocSize);
			if (status == B_OK)
				status = user_memcpy(arg, &info, sizeof(multi_mix_value_info));
			if (status != B_OK)
				status = B_BAD_ADDRESS;
			free(values);
			return status;
		}
		case B_MULTI_SET_MIX:
		{
			multi_mix_value_info info;
			multi_mix_value* original_values;
			size_t allocSize;
			multi_mix_value *values;

			if (user_memcpy(&info, arg, sizeof(multi_mix_value_info)) != B_OK)
				return B_BAD_ADDRESS;

			original_values = info.values;
			allocSize = sizeof(multi_mix_value) * info.item_count;
			values = (multi_mix_value *)malloc(allocSize);
			if (values == NULL)
				return B_NO_MEMORY;

			if (!IS_USER_ADDRESS(info.values)
				|| user_memcpy(values, info.values, allocSize) < B_OK) {
				free(values);
				return B_BAD_ADDRESS;
			}
			info.values = values;

			status = set_mix(cookie, &info);
			if (status != B_OK) {
				free(values);
				return status;
			}

			info.values = original_values;
			status = user_memcpy(info.values, values, allocSize);
			if (status == B_OK)
				status = user_memcpy(arg, &info, sizeof(multi_mix_value_info));
			if (status != B_OK)
				status = B_BAD_ADDRESS;
			free(values);
			return status;
		}
		case B_MULTI_GET_BUFFERS:
		{
			multi_buffer_list list;
			if (user_memcpy(&list, arg, sizeof(multi_buffer_list)) != B_OK)
				return B_BAD_ADDRESS;
			{
				buffer_desc **original_playback_descs = list.playback_buffers;
				buffer_desc **original_record_descs = list.record_buffers;

				buffer_desc *playback_descs[list.request_playback_buffers];
				buffer_desc *record_descs[list.request_record_buffers];

				if (!IS_USER_ADDRESS(list.playback_buffers)
					|| user_memcpy(playback_descs, list.playback_buffers,
						sizeof(buffer_desc*) * list.request_playback_buffers)
						< B_OK
					|| !IS_USER_ADDRESS(list.record_buffers)
					|| user_memcpy(record_descs, list.record_buffers,
						sizeof(buffer_desc*) * list.request_record_buffers)
						< B_OK) {
					return B_BAD_ADDRESS;
				}

				list.playback_buffers = playback_descs;
				list.record_buffers = record_descs;
				status = get_buffers(cookie, &list);
				if (status != B_OK)
					return status;

				list.playback_buffers = original_playback_descs;
				list.record_buffers = original_record_descs;

				if (user_memcpy(arg, &list, sizeof(multi_buffer_list)) < B_OK
					|| user_memcpy(original_playback_descs, playback_descs,
						sizeof(buffer_desc*) * list.request_playback_buffers)
						< B_OK
					|| user_memcpy(original_record_descs, record_descs,
						sizeof(buffer_desc*) * list.request_record_buffers)
						< B_OK) {
					status = B_BAD_ADDRESS;
				}
			}

			return status;
		}
		case B_MULTI_BUFFER_EXCHANGE:
			return buffer_exchange(cookie, (multi_buffer_info*)arg);
		case B_MULTI_BUFFER_FORCE_STOP:
			return buffer_force_stop(cookie);

		case B_MULTI_GET_EVENT_INFO:
		case B_MULTI_SET_EVENT_INFO:
		case B_MULTI_GET_EVENT:
		case B_MULTI_GET_CHANNEL_FORMATS:
		case B_MULTI_SET_CHANNEL_FORMATS:
		case B_MULTI_SET_BUFFERS:
		case B_MULTI_SET_START_TIME:
			return B_ERROR;
	}

	return B_BAD_VALUE;
}
Exemple #9
0
int aa_umount(struct aa_label *label, struct vfsmount *mnt, int flags)
{
	struct aa_profile *profile;
	char *buffer = NULL;
	int error;
	struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };

	AA_BUG(!label);
	AA_BUG(!mnt);

	get_buffers(buffer);
	error = fn_for_each_confined(label, profile,
			profile_umount(profile, &path, buffer));
	put_buffers(buffer);

	return error;
}

/* helper fn for transition on pivotroot
 *
 * Returns: label for transition or ERR_PTR. Does not return NULL
 */
static struct aa_label *build_pivotroot(struct aa_profile *profile,
					const struct path *new_path,
					char *new_buffer,
					const struct path *old_path,
					char *old_buffer)
{
	const char *old_name, *new_name = NULL, *info = NULL;
	const char *trans_name = NULL;
	struct aa_perms perms = { };
	unsigned int state;
	int error;

	AA_BUG(!profile);
	AA_BUG(!new_path);
	AA_BUG(!old_path);

	if (profile_unconfined(profile) ||
	    !PROFILE_MEDIATES(profile, AA_CLASS_MOUNT))
		return aa_get_newest_label(&profile->label);

	error = aa_path_name(old_path, path_flags(profile, old_path),
			     old_buffer, &old_name, &info,
			     profile->disconnected);
	if (error)
		goto audit;
	error = aa_path_name(new_path, path_flags(profile, new_path),
			     new_buffer, &new_name, &info,
			     profile->disconnected);
	if (error)
		goto audit;

	error = -EACCES;
	state = aa_dfa_match(profile->policy.dfa,
			     profile->policy.start[AA_CLASS_MOUNT],
			     new_name);
	state = aa_dfa_null_transition(profile->policy.dfa, state);
	state = aa_dfa_match(profile->policy.dfa, state, old_name);
	perms = compute_mnt_perms(profile->policy.dfa, state);

	if (AA_MAY_PIVOTROOT & perms.allow)
		error = 0;

audit:
	error = audit_mount(profile, OP_PIVOTROOT, new_name, old_name,
			    NULL, trans_name, 0, NULL, AA_MAY_PIVOTROOT,
			    &perms, info, error);
	if (error)
		return ERR_PTR(error);

	return aa_get_newest_label(&profile->label);
}

int aa_pivotroot(struct aa_label *label, const struct path *old_path,
		 const struct path *new_path)
{
	struct aa_profile *profile;
	struct aa_label *target = NULL;
	char *old_buffer = NULL, *new_buffer = NULL, *info = NULL;
	int error;

	AA_BUG(!label);
	AA_BUG(!old_path);
	AA_BUG(!new_path);

	get_buffers(old_buffer, new_buffer);
	target = fn_label_build(label, profile, GFP_ATOMIC,
			build_pivotroot(profile, new_path, new_buffer,
					old_path, old_buffer));
	if (!target) {
		info = "label build failed";
		error = -ENOMEM;
		goto fail;
	} else if (!IS_ERR(target)) {
		error = aa_replace_current_label(target);
		if (error) {
			/* TODO: audit target */
			aa_put_label(target);
			goto out;
		}
	} else
		/* already audited error */
		error = PTR_ERR(target);
out:
	put_buffers(old_buffer, new_buffer);

	return error;

fail:
	/* TODO: add back in auditing of new_name and old_name */
	error = fn_for_each(label, profile,
			audit_mount(profile, OP_PIVOTROOT, NULL /*new_name */,
				    NULL /* old_name */,
				    NULL, NULL,
				    0, NULL, AA_MAY_PIVOTROOT, &nullperms, info,
				    error));
	goto out;
}
Exemple #10
0
void
PortImpl::prepare_poly_buffers(BufferFactory& bufs)
{
	if (_prepared_buffers)
		get_buffers(bufs, _prepared_buffers, _prepared_buffers->size());
}
Exemple #11
0
std::vector<RAPDU> ICard::transceive(const std::vector<CAPDU> &cmds)
{
	return get_rapdus(m_subSystem->transceive(get_buffers(cmds)));
}
Exemple #12
0
mem_buf_desc_t *buffer_pool::get_buffers_thread_safe(size_t count, uint32_t lkey)
{
	auto_unlocker lock(m_lock_spin);
	return get_buffers(count, lkey);
}