diff options
-rw-r--r-- | auth-rhosts.c | 6 | ||||
-rw-r--r-- | auth.c | 9 | ||||
-rw-r--r-- | misc.c | 69 | ||||
-rw-r--r-- | misc.h | 2 | ||||
-rw-r--r-- | platform.c | 16 | ||||
-rw-r--r-- | readconf.c | 5 | ||||
-rw-r--r-- | ssh.1 | 2 | ||||
-rw-r--r-- | ssh_config.5 | 2 |
8 files changed, 82 insertions, 29 deletions
diff --git a/auth-rhosts.c b/auth-rhosts.c index 06ae7f0b9..f20278797 100644 --- a/auth-rhosts.c +++ b/auth-rhosts.c | |||
@@ -256,8 +256,7 @@ auth_rhosts2_raw(struct passwd *pw, const char *client_user, const char *hostnam | |||
256 | return 0; | 256 | return 0; |
257 | } | 257 | } |
258 | if (options.strict_modes && | 258 | if (options.strict_modes && |
259 | ((st.st_uid != 0 && st.st_uid != pw->pw_uid) || | 259 | !secure_permissions(&st, pw->pw_uid)) { |
260 | (st.st_mode & 022) != 0)) { | ||
261 | logit("Rhosts authentication refused for %.100s: " | 260 | logit("Rhosts authentication refused for %.100s: " |
262 | "bad ownership or modes for home directory.", pw->pw_name); | 261 | "bad ownership or modes for home directory.", pw->pw_name); |
263 | auth_debug_add("Rhosts authentication refused for %.100s: " | 262 | auth_debug_add("Rhosts authentication refused for %.100s: " |
@@ -283,8 +282,7 @@ auth_rhosts2_raw(struct passwd *pw, const char *client_user, const char *hostnam | |||
283 | * allowing access to their account by anyone. | 282 | * allowing access to their account by anyone. |
284 | */ | 283 | */ |
285 | if (options.strict_modes && | 284 | if (options.strict_modes && |
286 | ((st.st_uid != 0 && st.st_uid != pw->pw_uid) || | 285 | !secure_permissions(&st, pw->pw_uid)) { |
287 | (st.st_mode & 022) != 0)) { | ||
288 | logit("Rhosts authentication refused for %.100s: bad modes for %.200s", | 286 | logit("Rhosts authentication refused for %.100s: bad modes for %.200s", |
289 | pw->pw_name, buf); | 287 | pw->pw_name, buf); |
290 | auth_debug_add("Bad file modes for %.200s", buf); | 288 | auth_debug_add("Bad file modes for %.200s", buf); |
@@ -407,8 +407,7 @@ check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host, | |||
407 | user_hostfile = tilde_expand_filename(userfile, pw->pw_uid); | 407 | user_hostfile = tilde_expand_filename(userfile, pw->pw_uid); |
408 | if (options.strict_modes && | 408 | if (options.strict_modes && |
409 | (stat(user_hostfile, &st) == 0) && | 409 | (stat(user_hostfile, &st) == 0) && |
410 | ((st.st_uid != 0 && st.st_uid != pw->pw_uid) || | 410 | !secure_permissions(&st, pw->pw_uid)) { |
411 | (st.st_mode & 022) != 0)) { | ||
412 | logit("Authentication refused for %.100s: " | 411 | logit("Authentication refused for %.100s: " |
413 | "bad owner or modes for %.200s", | 412 | "bad owner or modes for %.200s", |
414 | pw->pw_name, user_hostfile); | 413 | pw->pw_name, user_hostfile); |
@@ -470,8 +469,7 @@ auth_secure_path(const char *name, struct stat *stp, const char *pw_dir, | |||
470 | snprintf(err, errlen, "%s is not a regular file", buf); | 469 | snprintf(err, errlen, "%s is not a regular file", buf); |
471 | return -1; | 470 | return -1; |
472 | } | 471 | } |
473 | if ((!platform_sys_dir_uid(stp->st_uid) && stp->st_uid != uid) || | 472 | if (!secure_permissions(stp, uid)) { |
474 | (stp->st_mode & 022) != 0) { | ||
475 | snprintf(err, errlen, "bad ownership or modes for file %s", | 473 | snprintf(err, errlen, "bad ownership or modes for file %s", |
476 | buf); | 474 | buf); |
477 | return -1; | 475 | return -1; |
@@ -486,8 +484,7 @@ auth_secure_path(const char *name, struct stat *stp, const char *pw_dir, | |||
486 | strlcpy(buf, cp, sizeof(buf)); | 484 | strlcpy(buf, cp, sizeof(buf)); |
487 | 485 | ||
488 | if (stat(buf, &st) < 0 || | 486 | if (stat(buf, &st) < 0 || |
489 | (!platform_sys_dir_uid(st.st_uid) && st.st_uid != uid) || | 487 | !secure_permissions(&st, uid)) { |
490 | (st.st_mode & 022) != 0) { | ||
491 | snprintf(err, errlen, | 488 | snprintf(err, errlen, |
492 | "bad ownership or modes for directory %s", buf); | 489 | "bad ownership or modes for directory %s", buf); |
493 | return -1; | 490 | return -1; |
@@ -49,8 +49,9 @@ | |||
49 | #include <netdb.h> | 49 | #include <netdb.h> |
50 | #ifdef HAVE_PATHS_H | 50 | #ifdef HAVE_PATHS_H |
51 | # include <paths.h> | 51 | # include <paths.h> |
52 | #include <pwd.h> | ||
53 | #endif | 52 | #endif |
53 | #include <pwd.h> | ||
54 | #include <grp.h> | ||
54 | #ifdef SSH_TUN_OPENBSD | 55 | #ifdef SSH_TUN_OPENBSD |
55 | #include <net/if.h> | 56 | #include <net/if.h> |
56 | #endif | 57 | #endif |
@@ -59,6 +60,7 @@ | |||
59 | #include "misc.h" | 60 | #include "misc.h" |
60 | #include "log.h" | 61 | #include "log.h" |
61 | #include "ssh.h" | 62 | #include "ssh.h" |
63 | #include "platform.h" | ||
62 | 64 | ||
63 | /* remove newline at end of string */ | 65 | /* remove newline at end of string */ |
64 | char * | 66 | char * |
@@ -643,6 +645,71 @@ read_keyfile_line(FILE *f, const char *filename, char *buf, size_t bufsz, | |||
643 | return -1; | 645 | return -1; |
644 | } | 646 | } |
645 | 647 | ||
648 | /* | ||
649 | * return 1 if the specified uid is a uid that may own a system directory | ||
650 | * otherwise 0. | ||
651 | */ | ||
652 | int | ||
653 | platform_sys_dir_uid(uid_t uid) | ||
654 | { | ||
655 | if (uid == 0) | ||
656 | return 1; | ||
657 | #ifdef PLATFORM_SYS_DIR_UID | ||
658 | if (uid == PLATFORM_SYS_DIR_UID) | ||
659 | return 1; | ||
660 | #endif | ||
661 | return 0; | ||
662 | } | ||
663 | |||
664 | int | ||
665 | secure_permissions(struct stat *st, uid_t uid) | ||
666 | { | ||
667 | if (!platform_sys_dir_uid(st->st_uid) && st->st_uid != uid) | ||
668 | return 0; | ||
669 | if ((st->st_mode & 002) != 0) | ||
670 | return 0; | ||
671 | if ((st->st_mode & 020) != 0) { | ||
672 | /* If the file is group-writable, the group in question must | ||
673 | * have exactly one member, namely the file's owner. | ||
674 | * (Zero-member groups are typically used by setgid | ||
675 | * binaries, and are unlikely to be suitable.) | ||
676 | */ | ||
677 | struct passwd *pw; | ||
678 | struct group *gr; | ||
679 | int members = 0; | ||
680 | |||
681 | gr = getgrgid(st->st_gid); | ||
682 | if (!gr) | ||
683 | return 0; | ||
684 | |||
685 | /* Check primary group memberships. */ | ||
686 | while ((pw = getpwent()) != NULL) { | ||
687 | if (pw->pw_gid == gr->gr_gid) { | ||
688 | ++members; | ||
689 | if (pw->pw_uid != uid) | ||
690 | return 0; | ||
691 | } | ||
692 | } | ||
693 | endpwent(); | ||
694 | |||
695 | pw = getpwuid(st->st_uid); | ||
696 | if (!pw) | ||
697 | return 0; | ||
698 | |||
699 | /* Check supplementary group memberships. */ | ||
700 | if (gr->gr_mem[0]) { | ||
701 | ++members; | ||
702 | if (strcmp(pw->pw_name, gr->gr_mem[0]) || | ||
703 | gr->gr_mem[1]) | ||
704 | return 0; | ||
705 | } | ||
706 | |||
707 | if (!members) | ||
708 | return 0; | ||
709 | } | ||
710 | return 1; | ||
711 | } | ||
712 | |||
646 | int | 713 | int |
647 | tun_open(int tun, int mode) | 714 | tun_open(int tun, int mode) |
648 | { | 715 | { |
@@ -106,4 +106,6 @@ char *read_passphrase(const char *, int); | |||
106 | int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2))); | 106 | int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2))); |
107 | int read_keyfile_line(FILE *, const char *, char *, size_t, u_long *); | 107 | int read_keyfile_line(FILE *, const char *, char *, size_t, u_long *); |
108 | 108 | ||
109 | int secure_permissions(struct stat *st, uid_t uid); | ||
110 | |||
109 | #endif /* _MISC_H */ | 111 | #endif /* _MISC_H */ |
diff --git a/platform.c b/platform.c index 4aab9a9cd..f99de7fab 100644 --- a/platform.c +++ b/platform.c | |||
@@ -196,19 +196,3 @@ platform_krb5_get_principal_name(const char *pw_name) | |||
196 | return NULL; | 196 | return NULL; |
197 | #endif | 197 | #endif |
198 | } | 198 | } |
199 | |||
200 | /* | ||
201 | * return 1 if the specified uid is a uid that may own a system directory | ||
202 | * otherwise 0. | ||
203 | */ | ||
204 | int | ||
205 | platform_sys_dir_uid(uid_t uid) | ||
206 | { | ||
207 | if (uid == 0) | ||
208 | return 1; | ||
209 | #ifdef PLATFORM_SYS_DIR_UID | ||
210 | if (uid == PLATFORM_SYS_DIR_UID) | ||
211 | return 1; | ||
212 | #endif | ||
213 | return 0; | ||
214 | } | ||
diff --git a/readconf.c b/readconf.c index 640993732..32c4b425b 100644 --- a/readconf.c +++ b/readconf.c | |||
@@ -37,6 +37,8 @@ | |||
37 | #include <stdio.h> | 37 | #include <stdio.h> |
38 | #include <string.h> | 38 | #include <string.h> |
39 | #include <unistd.h> | 39 | #include <unistd.h> |
40 | #include <pwd.h> | ||
41 | #include <grp.h> | ||
40 | #ifdef HAVE_UTIL_H | 42 | #ifdef HAVE_UTIL_H |
41 | #include <util.h> | 43 | #include <util.h> |
42 | #endif | 44 | #endif |
@@ -1477,8 +1479,7 @@ read_config_file(const char *filename, struct passwd *pw, const char *host, | |||
1477 | 1479 | ||
1478 | if (fstat(fileno(f), &sb) == -1) | 1480 | if (fstat(fileno(f), &sb) == -1) |
1479 | fatal("fstat %s: %s", filename, strerror(errno)); | 1481 | fatal("fstat %s: %s", filename, strerror(errno)); |
1480 | if (((sb.st_uid != 0 && sb.st_uid != getuid()) || | 1482 | if (!secure_permissions(&sb, getuid())) |
1481 | (sb.st_mode & 022) != 0)) | ||
1482 | fatal("Bad owner or permissions on %s", filename); | 1483 | fatal("Bad owner or permissions on %s", filename); |
1483 | } | 1484 | } |
1484 | 1485 | ||
@@ -1352,6 +1352,8 @@ The file format and configuration options are described in | |||
1352 | .Xr ssh_config 5 . | 1352 | .Xr ssh_config 5 . |
1353 | Because of the potential for abuse, this file must have strict permissions: | 1353 | Because of the potential for abuse, this file must have strict permissions: |
1354 | read/write for the user, and not writable by others. | 1354 | read/write for the user, and not writable by others. |
1355 | It may be group-writable provided that the group in question contains only | ||
1356 | the user. | ||
1355 | .Pp | 1357 | .Pp |
1356 | .It Pa ~/.ssh/environment | 1358 | .It Pa ~/.ssh/environment |
1357 | Contains additional definitions for environment variables; see | 1359 | Contains additional definitions for environment variables; see |
diff --git a/ssh_config.5 b/ssh_config.5 index 3172fd441..4bf7cbb3c 100644 --- a/ssh_config.5 +++ b/ssh_config.5 | |||
@@ -1529,6 +1529,8 @@ The format of this file is described above. | |||
1529 | This file is used by the SSH client. | 1529 | This file is used by the SSH client. |
1530 | Because of the potential for abuse, this file must have strict permissions: | 1530 | Because of the potential for abuse, this file must have strict permissions: |
1531 | read/write for the user, and not accessible by others. | 1531 | read/write for the user, and not accessible by others. |
1532 | It may be group-writable provided that the group in question contains only | ||
1533 | the user. | ||
1532 | .It Pa /etc/ssh/ssh_config | 1534 | .It Pa /etc/ssh/ssh_config |
1533 | Systemwide configuration file. | 1535 | Systemwide configuration file. |
1534 | This file provides defaults for those | 1536 | This file provides defaults for those |