Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xcap-capability-linux
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
xcap
xcap-capability-linux
Commits
d7ed89f8
Commit
d7ed89f8
authored
Mar 20, 2014
by
Sarah Spall
Committed by
Vikram Narayanan
Oct 25, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added init_lcd system call, and insmod4lcd2.c is file that is supposed to use this system call
parent
fac951d9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
347 additions
and
2 deletions
+347
-2
arch/x86/entry/syscalls/syscall_32.tbl
arch/x86/entry/syscalls/syscall_32.tbl
+1
-0
arch/x86/lcd/lcd_defs.h
arch/x86/lcd/lcd_defs.h
+3
-0
arch/x86/lcd/lcd_main.c
arch/x86/lcd/lcd_main.c
+1
-1
arch/x86/lcd/tools/insmod4lcd2.c
arch/x86/lcd/tools/insmod4lcd2.c
+177
-0
include/linux/syscalls.h
include/linux/syscalls.h
+3
-0
kernel/module.c
kernel/module.c
+161
-0
tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
+1
-1
No files found.
arch/x86/entry/syscalls/syscall_32.tbl
View file @
d7ed89f8
...
...
@@ -386,3 +386,4 @@
377 i386 copy_file_range sys_copy_file_range
378 i386 preadv2 sys_preadv2 compat_sys_preadv2
379 i386 pwritev2 sys_pwritev2 compat_sys_pwritev2
380 i386 init_lcd sys_init_lcd
arch/x86/lcd/lcd_defs.h
View file @
d7ed89f8
...
...
@@ -3,6 +3,7 @@
#include <linux/bitmap.h>
#include <uapi/asm/bootparam.h>
#include <asm/vmx.h>
#if !defined(VMX_EPT_AD_BIT)
#define VMX_EPT_AD_BIT (1ull << 21)
...
...
@@ -246,6 +247,8 @@ typedef struct {
#define LCD_FREE_MEM_START (LCD_ISR_END + PAGE_SIZE)
#define LCD_TEST_CODE_ADDR LCD_FREE_MEM_START
//static int load_lcd(struct load_info * info, const char __user *uargs, int flags);
/* Exported functions */
lcd_struct
*
lcd_create
(
void
);
int
lcd_destroy
(
lcd_struct
*
lcd
);
...
...
arch/x86/lcd/lcd_main.c
View file @
d7ed89f8
...
...
@@ -16,7 +16,7 @@
#include <uapi/asm/kvm.h>
#include <asm/vmx.h>
//
#include <asm/vmx.h>
#include <asm/processor.h>
#include <asm/desc.h>
#include <asm/virtext.h>
...
...
arch/x86/lcd/tools/insmod4lcd2.c
0 → 100644
View file @
d7ed89f8
/* insmod.c: insert a module into the kernel.
Copyright (C) 2001 Rusty Russell.
Copyright (C) 2002 Rusty Russell, IBM Corporation.
Copyright (C) 2014 Weibin Sun, Flux
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <asm/unistd.h>
//extern long init_lcd(void *, unsigned long, const char *);
static
char
*
my_basename
(
const
char
*
path
)
{
const
char
*
base
=
strrchr
(
path
,
'/'
);
if
(
base
)
return
(
char
*
)
base
+
1
;
return
(
char
*
)
path
;
}
#define streq(a,b) (strcmp((a),(b)) == 0)
static
void
print_usage
(
const
char
*
progname
)
{
fprintf
(
stderr
,
"Usage: %s filename [args]
\n
"
,
progname
);
exit
(
1
);
}
/* We use error numbers in a loose translation... */
static
const
char
*
moderror
(
int
err
)
{
switch
(
err
)
{
case
ENOEXEC
:
return
"Invalid module format"
;
case
ENOENT
:
return
"Unknown symbol in module"
;
case
ESRCH
:
return
"Module has wrong symbol version"
;
case
EINVAL
:
return
"Invalid parameters"
;
default:
return
strerror
(
err
);
}
}
static
void
*
grab_file
(
const
char
*
filename
,
unsigned
long
*
size
)
{
unsigned
int
max
=
16384
;
int
ret
,
fd
,
err_save
;
void
*
buffer
;
if
(
streq
(
filename
,
"-"
))
fd
=
dup
(
STDIN_FILENO
);
else
fd
=
open
(
filename
,
O_RDONLY
,
0
);
if
(
fd
<
0
)
return
NULL
;
buffer
=
malloc
(
max
);
if
(
!
buffer
)
goto
out_error
;
*
size
=
0
;
while
((
ret
=
read
(
fd
,
buffer
+
*
size
,
max
-
*
size
))
>
0
)
{
*
size
+=
ret
;
if
(
*
size
==
max
)
{
void
*
p
;
p
=
realloc
(
buffer
,
max
*=
2
);
if
(
!
p
)
goto
out_error
;
buffer
=
p
;
}
}
if
(
ret
<
0
)
goto
out_error
;
close
(
fd
);
return
buffer
;
out_error:
err_save
=
errno
;
free
(
buffer
);
close
(
fd
);
errno
=
err_save
;
return
NULL
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
unsigned
int
i
;
long
int
ret
;
unsigned
long
len
;
void
*
file
;
char
*
filename
,
*
options
=
strdup
(
""
);
char
*
p
,
*
progname
=
argv
[
0
];
if
(
!
options
)
{
fprintf
(
stderr
,
"insmod: can't allocate memory: %s
\n
"
,
strerror
(
errno
));
exit
(
1
);
}
p
=
my_basename
(
argv
[
0
]);
if
(
argv
[
1
]
&&
(
streq
(
argv
[
1
],
"--version"
)
||
streq
(
argv
[
1
],
"-V"
)))
{
puts
(
"Specialied insmod for LCD
\n
"
);
exit
(
0
);
}
/* Ignore old options, for backwards compat. */
while
(
argv
[
1
]
&&
(
streq
(
argv
[
1
],
"-p"
)
||
streq
(
argv
[
1
],
"-s"
)
||
streq
(
argv
[
1
],
"-f"
)))
{
argv
++
;
argc
--
;
}
filename
=
argv
[
1
];
if
(
!
filename
)
print_usage
(
progname
);
/* Rest is options */
for
(
i
=
2
;
i
<
argc
;
i
++
)
{
options
=
realloc
(
options
,
strlen
(
options
)
+
1
+
strlen
(
argv
[
i
])
+
1
);
if
(
!
options
)
{
fprintf
(
stderr
,
"insmod: can't allocate memory: %s
\n
"
,
strerror
(
errno
));
exit
(
1
);
}
strcat
(
options
,
argv
[
i
]);
strcat
(
options
,
" "
);
}
file
=
grab_file
(
filename
,
&
len
);
if
(
!
file
)
{
fprintf
(
stderr
,
"insmod: can't read '%s': %s
\n
"
,
filename
,
strerror
(
errno
));
exit
(
1
);
}
printf
(
"gets to call"
);
ret
=
syscall
(
351
,
file
,
len
,
options
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"insmod: error inserting '%s': %li %s
\n
"
,
filename
,
ret
,
moderror
(
errno
));
}
free
(
file
);
if
(
ret
!=
0
)
exit
(
1
);
exit
(
0
);
}
include/linux/syscalls.h
View file @
d7ed89f8
...
...
@@ -881,6 +881,7 @@ asmlinkage long sys_process_vm_writev(pid_t pid,
asmlinkage
long
sys_kcmp
(
pid_t
pid1
,
pid_t
pid2
,
int
type
,
unsigned
long
idx1
,
unsigned
long
idx2
);
asmlinkage
long
sys_finit_module
(
int
fd
,
const
char
__user
*
uargs
,
int
flags
);
asmlinkage
long
sys_seccomp
(
unsigned
int
op
,
unsigned
int
flags
,
const
char
__user
*
uargs
);
asmlinkage
long
sys_getrandom
(
char
__user
*
buf
,
size_t
count
,
...
...
@@ -898,4 +899,6 @@ asmlinkage long sys_copy_file_range(int fd_in, loff_t __user *off_in,
asmlinkage
long
sys_mlock2
(
unsigned
long
start
,
size_t
len
,
int
flags
);
asmlinkage
long
sys_init_lcd
(
void
__user
*
umod
,
unsigned
long
len
,
const
char
__user
*
uargs
);
#endif
kernel/module.c
View file @
d7ed89f8
...
...
@@ -63,6 +63,7 @@
#include <linux/dynamic_debug.h>
#include <uapi/linux/module.h>
#include "module-internal.h"
#include <../lcd/lcd_defs.h>
#define CREATE_TRACE_POINTS
#include <trace/events/module.h>
...
...
@@ -3751,6 +3752,166 @@ static int load_module(struct load_info *info, const char __user *uargs,
return
err
;
}
static
int
load_lcd
(
struct
load_info
*
info
,
const
char
__user
*
uargs
,
int
flags
)
{
lcd_struct
*
lcd
;
struct
module
*
mod
;
long
err
;
err
=
module_sig_check
(
info
);
if
(
err
)
goto
free_copy
;
err
=
elf_header_check
(
info
);
if
(
err
)
goto
free_copy
;
/* Figure out module layout, and allocate all the memory. */
mod
=
layout_and_allocate
(
info
,
flags
);
if
(
IS_ERR
(
mod
))
{
err
=
PTR_ERR
(
mod
);
goto
free_copy
;
}
/* Reserve our place in the list. */
err
=
add_unformed_module
(
mod
);
if
(
err
)
goto
free_module
;
#ifdef CONFIG_MODULE_SIG
mod
->
sig_ok
=
info
->
sig_ok
;
if
(
!
mod
->
sig_ok
)
{
printk_once
(
KERN_NOTICE
"%s: module verification failed: signature and/or"
" required key missing - tainting kernel
\n
"
,
mod
->
name
);
add_taint_module
(
mod
,
TAINT_FORCED_MODULE
,
LOCKDEP_STILL_OK
);
}
#endif
/* To avoid stressing percpu allocator, do this once we're unique. */
err
=
alloc_module_percpu
(
mod
,
info
);
if
(
err
)
goto
unlink_mod
;
/* Now module is in final location, initialize linked lists, etc. */
err
=
module_unload_init
(
mod
);
if
(
err
)
goto
unlink_mod
;
/* Now we've got everything in the final locations, we can
* find optional sections. */
find_module_sections
(
mod
,
info
);
err
=
check_module_license_and_versions
(
mod
);
if
(
err
)
goto
free_unload
;
/* Set up MODINFO_ATTR fields */
setup_modinfo
(
mod
,
info
);
/* Fix up syms, so that st_value is a pointer to location. */
err
=
simplify_symbols
(
mod
,
info
);
if
(
err
<
0
)
goto
free_modinfo
;
err
=
apply_relocations
(
mod
,
info
);
if
(
err
<
0
)
goto
free_modinfo
;
err
=
post_relocation
(
mod
,
info
);
if
(
err
<
0
)
goto
free_modinfo
;
flush_module_icache
(
mod
);
/* Now copy in args */
mod
->
args
=
strndup_user
(
uargs
,
~
0UL
>>
1
);
if
(
IS_ERR
(
mod
->
args
))
{
err
=
PTR_ERR
(
mod
->
args
);
goto
free_arch_cleanup
;
}
dynamic_debug_setup
(
info
->
debug
,
info
->
num_debug
);
/* Finally it's fully formed, ready to start executing. */
err
=
complete_formation
(
mod
,
info
);
if
(
err
)
goto
ddebug_cleanup
;
/* Module is ready to execute: parsing args may do that. */
err
=
parse_args
(
mod
->
name
,
mod
->
args
,
mod
->
kp
,
mod
->
num_kp
,
-
32768
,
32767
,
&
ddebug_dyndbg_module_param_cb
);
if
(
err
<
0
)
goto
bug_cleanup
;
/* Link in to syfs. */
err
=
mod_sysfs_setup
(
mod
,
info
,
mod
->
kp
,
mod
->
num_kp
);
if
(
err
<
0
)
goto
bug_cleanup
;
/* Get rid of temporary copy. */
free_copy
(
info
);
/* Done! */
trace_module_load
(
mod
);
lcd
=
lcd_create
();
lcd_move_module
(
lcd
,
mod
);
lcd_run
(
lcd
);
return
0
;
// return do_init_module(mod);
bug_cleanup:
/* module_bug_cleanup needs module_mutex protection */
mutex_lock
(
&
module_mutex
);
module_bug_cleanup
(
mod
);
mutex_unlock
(
&
module_mutex
);
ddebug_cleanup:
dynamic_debug_remove
(
info
->
debug
);
synchronize_sched
();
kfree
(
mod
->
args
);
free_arch_cleanup:
module_arch_cleanup
(
mod
);
free_modinfo:
free_modinfo
(
mod
);
free_unload:
module_unload_free
(
mod
);
unlink_mod:
mutex_lock
(
&
module_mutex
);
/* Unlink carefully: kallsyms could be walking list. */
list_del_rcu
(
&
mod
->
list
);
wake_up_all
(
&
module_wq
);
mutex_unlock
(
&
module_mutex
);
free_module:
module_deallocate
(
mod
,
info
);
free_copy:
free_copy
(
info
);
return
err
;
}
SYSCALL_DEFINE3
(
init_lcd
,
void
__user
*
,
umod
,
unsigned
long
,
len
,
const
char
__user
*
,
uargs
)
{
int
err
;
struct
load_info
info
=
{
};
err
=
may_init_module
();
if
(
err
)
return
err
;
pr_debug
(
"init_module: umod=%p, len=%lu, uargs=%p
\n
"
,
umod
,
len
,
uargs
);
err
=
copy_module_from_user
(
umod
,
len
,
&
info
);
if
(
err
)
return
err
;
return
load_lcd
(
&
info
,
uargs
,
0
);
}
SYSCALL_DEFINE3
(
init_module
,
void
__user
*
,
umod
,
unsigned
long
,
len
,
const
char
__user
*
,
uargs
)
{
...
...
tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
View file @
d7ed89f8
...
...
@@ -335,7 +335,7 @@
326 common copy_file_range sys_copy_file_range
327 64 preadv2 sys_preadv2
328 64 pwritev2 sys_pwritev2
329 common init_lcd sys_init_lcd
#
# x32-specific system call numbers start at 512 to avoid cache impact
# for native 64-bit operation.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment