-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hardening xrdp with AppArmor #2265
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,9 @@ | |
#include <sys/stat.h> | ||
#include <sys/ipc.h> | ||
#include <sys/shm.h> | ||
#if defined(HAVE_SYS_PRCTL_H) | ||
#include <sys/prctl.h> | ||
#endif | ||
#include <dlfcn.h> | ||
#include <arpa/inet.h> | ||
#include <netdb.h> | ||
|
@@ -2086,24 +2089,14 @@ g_memcmp(const void *s1, const void *s2, int len) | |
/*****************************************************************************/ | ||
/* returns -1 on error, else return handle or file descriptor */ | ||
int | ||
g_file_open(const char *file_name) | ||
g_file_open_rw(const char *file_name) | ||
{ | ||
#if defined(_WIN32) | ||
return (int)CreateFileA(file_name, GENERIC_READ | GENERIC_WRITE, | ||
FILE_SHARE_READ | FILE_SHARE_WRITE, | ||
0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); | ||
#else | ||
int rv; | ||
|
||
rv = open(file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); | ||
|
||
if (rv == -1) | ||
{ | ||
/* can't open read / write, try to open read only */ | ||
rv = open(file_name, O_RDONLY); | ||
} | ||
|
||
return rv; | ||
return open(file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); | ||
#endif | ||
} | ||
|
||
|
@@ -2145,6 +2138,14 @@ g_file_open_ex(const char *file_name, int aread, int awrite, | |
#endif | ||
} | ||
|
||
/*****************************************************************************/ | ||
/* returns -1 on error, else return handle or file descriptor */ | ||
int | ||
g_file_open_ro(const char *file_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I like this idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do too. I'm also quite happy with the idea of setting up a |
||
{ | ||
return g_file_open_ex(file_name, 1, 0, 0, 0); | ||
} | ||
|
||
/*****************************************************************************/ | ||
/* returns error, always 0 */ | ||
int | ||
|
@@ -3956,3 +3957,19 @@ g_tcp6_bind_address(int sck, const char *port, const char *address) | |
return -1; | ||
#endif | ||
} | ||
|
||
/*****************************************************************************/ | ||
/* returns error, zero is success, non zero is error */ | ||
/* only works in linux */ | ||
int | ||
g_no_new_privs(void) | ||
{ | ||
#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NO_NEW_PRIVS) | ||
/* | ||
* PR_SET_NO_NEW_PRIVS requires Linux kernel 3.5 and newer. | ||
*/ | ||
return prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); | ||
#else | ||
return 0; | ||
#endif | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code's not visible here, but in
g_file_open_rw()
, remove the fallback code for opening the file read-only.Also, in reply to a conversational comment I think having
_ro
and_rw
versions ofg_open_file
is a good idea.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. The
CreateFileA()
call ing_file_open_rw()
will need updating, however (I don't know the API well enough to do this myself) and I noticed thatg_file_open_ex()
doesn't work on Windows. Sog_file_open_ro()
will probably need a_WIN32
section of its own.ACK on not renaming
g_file_open_ro()
tog_file_open()
.