diff options
author | Geoff Greer <geoff@greer.fm> | 2018-04-12 17:38:24 -0700 |
---|---|---|
committer | Geoff Greer <geoff@greer.fm> | 2018-04-12 17:49:21 -0700 |
commit | ad6aa21c43bb87c917e21416f3ba448b634a98f8 (patch) | |
tree | 2e2eea866e21d7f3484ef8efde82b5a6a6a2bfb0 /swaylock/main.c | |
parent | Merge branch 'master' of github.com:swaywm/sway (diff) | |
download | sway-ad6aa21c43bb87c917e21416f3ba448b634a98f8.tar.gz sway-ad6aa21c43bb87c917e21416f3ba448b634a98f8.tar.zst sway-ad6aa21c43bb87c917e21416f3ba448b634a98f8.zip |
swaylock: Securely zero-out password.
- Replace char* with static array. Any chars > 1024 will be discarded.
- mlock() password buffer so it can't be written to swap.
- Clear password buffer after auth succeeds or fails.
This is basically the same treatment I gave the 0.15 branch in https://github.com/swaywm/sway/pull/1519
Diffstat (limited to 'swaylock/main.c')
-rw-r--r-- | swaylock/main.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index 4c6b44c6..200c1b5f 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
10 | #include <string.h> | 10 | #include <string.h> |
11 | #include <sys/mman.h> | ||
11 | #include <sys/stat.h> | 12 | #include <sys/stat.h> |
12 | #include <time.h> | 13 | #include <time.h> |
13 | #include <unistd.h> | 14 | #include <unistd.h> |
@@ -18,10 +19,15 @@ | |||
18 | #include "background-image.h" | 19 | #include "background-image.h" |
19 | #include "pool-buffer.h" | 20 | #include "pool-buffer.h" |
20 | #include "cairo.h" | 21 | #include "cairo.h" |
22 | #include "log.h" | ||
21 | #include "util.h" | 23 | #include "util.h" |
22 | #include "wlr-input-inhibitor-unstable-v1-client-protocol.h" | 24 | #include "wlr-input-inhibitor-unstable-v1-client-protocol.h" |
23 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 25 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
24 | 26 | ||
27 | void sway_terminate(int exit_code) { | ||
28 | exit(exit_code); | ||
29 | } | ||
30 | |||
25 | static void daemonize() { | 31 | static void daemonize() { |
26 | int fds[2]; | 32 | int fds[2]; |
27 | if (pipe(fds) != 0) { | 33 | if (pipe(fds) != 0) { |
@@ -236,6 +242,13 @@ int main(int argc, char **argv) { | |||
236 | } | 242 | } |
237 | } | 243 | } |
238 | 244 | ||
245 | #ifdef __linux__ | ||
246 | // Most non-linux platforms require root to mlock() | ||
247 | if (mlock(state.password.buffer, sizeof(state.password.buffer)) != 0) { | ||
248 | sway_abort("Unable to mlock() password memory."); | ||
249 | } | ||
250 | #endif | ||
251 | |||
239 | wl_list_init(&state.surfaces); | 252 | wl_list_init(&state.surfaces); |
240 | state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); | 253 | state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); |
241 | state.display = wl_display_connect(NULL); | 254 | state.display = wl_display_connect(NULL); |