diff options
author | Colin Watson <cjwatson@debian.org> | 2014-02-09 16:09:58 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2016-08-07 12:18:43 +0100 |
commit | 563974a78e937c4844e1198b5f6d79b8b2b5c600 (patch) | |
tree | ab2b821031f9b3d4dac7123b677dd6e8a93ac4d3 /misc.c | |
parent | 173d65e72989cba82502604da3f1336766c0cf0f (diff) |
Allow harmless group-writability
Allow secure files (~/.ssh/config, ~/.ssh/authorized_keys, etc.) to be
group-writable, provided that the group in question contains only the file's
owner. Rejected upstream for IMO incorrect reasons (e.g. a misunderstanding
about the contents of gr->gr_mem). Given that per-user groups and umask 002
are the default setup in Debian (for good reasons - this makes operating in
setgid directories with other groups much easier), we need to permit this by
default.
Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1060
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=314347
Last-Update: 2013-09-14
Patch-Name: user-group-modes.patch
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 69 |
1 files changed, 68 insertions, 1 deletions
@@ -51,8 +51,9 @@ | |||
51 | #include <netdb.h> | 51 | #include <netdb.h> |
52 | #ifdef HAVE_PATHS_H | 52 | #ifdef HAVE_PATHS_H |
53 | # include <paths.h> | 53 | # include <paths.h> |
54 | #include <pwd.h> | ||
55 | #endif | 54 | #endif |
55 | #include <pwd.h> | ||
56 | #include <grp.h> | ||
56 | #ifdef SSH_TUN_OPENBSD | 57 | #ifdef SSH_TUN_OPENBSD |
57 | #include <net/if.h> | 58 | #include <net/if.h> |
58 | #endif | 59 | #endif |
@@ -61,6 +62,7 @@ | |||
61 | #include "misc.h" | 62 | #include "misc.h" |
62 | #include "log.h" | 63 | #include "log.h" |
63 | #include "ssh.h" | 64 | #include "ssh.h" |
65 | #include "platform.h" | ||
64 | 66 | ||
65 | /* remove newline at end of string */ | 67 | /* remove newline at end of string */ |
66 | char * | 68 | char * |
@@ -708,6 +710,71 @@ read_keyfile_line(FILE *f, const char *filename, char *buf, size_t bufsz, | |||
708 | return -1; | 710 | return -1; |
709 | } | 711 | } |
710 | 712 | ||
713 | /* | ||
714 | * return 1 if the specified uid is a uid that may own a system directory | ||
715 | * otherwise 0. | ||
716 | */ | ||
717 | int | ||
718 | platform_sys_dir_uid(uid_t uid) | ||
719 | { | ||
720 | if (uid == 0) | ||
721 | return 1; | ||
722 | #ifdef PLATFORM_SYS_DIR_UID | ||
723 | if (uid == PLATFORM_SYS_DIR_UID) | ||
724 | return 1; | ||
725 | #endif | ||
726 | return 0; | ||
727 | } | ||
728 | |||
729 | int | ||
730 | secure_permissions(struct stat *st, uid_t uid) | ||
731 | { | ||
732 | if (!platform_sys_dir_uid(st->st_uid) && st->st_uid != uid) | ||
733 | return 0; | ||
734 | if ((st->st_mode & 002) != 0) | ||
735 | return 0; | ||
736 | if ((st->st_mode & 020) != 0) { | ||
737 | /* If the file is group-writable, the group in question must | ||
738 | * have exactly one member, namely the file's owner. | ||
739 | * (Zero-member groups are typically used by setgid | ||
740 | * binaries, and are unlikely to be suitable.) | ||
741 | */ | ||
742 | struct passwd *pw; | ||
743 | struct group *gr; | ||
744 | int members = 0; | ||
745 | |||
746 | gr = getgrgid(st->st_gid); | ||
747 | if (!gr) | ||
748 | return 0; | ||
749 | |||
750 | /* Check primary group memberships. */ | ||
751 | while ((pw = getpwent()) != NULL) { | ||
752 | if (pw->pw_gid == gr->gr_gid) { | ||
753 | ++members; | ||
754 | if (pw->pw_uid != uid) | ||
755 | return 0; | ||
756 | } | ||
757 | } | ||
758 | endpwent(); | ||
759 | |||
760 | pw = getpwuid(st->st_uid); | ||
761 | if (!pw) | ||
762 | return 0; | ||
763 | |||
764 | /* Check supplementary group memberships. */ | ||
765 | if (gr->gr_mem[0]) { | ||
766 | ++members; | ||
767 | if (strcmp(pw->pw_name, gr->gr_mem[0]) || | ||
768 | gr->gr_mem[1]) | ||
769 | return 0; | ||
770 | } | ||
771 | |||
772 | if (!members) | ||
773 | return 0; | ||
774 | } | ||
775 | return 1; | ||
776 | } | ||
777 | |||
711 | int | 778 | int |
712 | tun_open(int tun, int mode) | 779 | tun_open(int tun, int mode) |
713 | { | 780 | { |