Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] mkswap: Add warnings for insecure device permissions/owners
@ 2016-01-19 18:37 Wayne R. Roth
  2016-01-19 19:44 ` Mike Frysinger
  2016-01-20 10:30 ` Karel Zak
  0 siblings, 2 replies; 18+ messages in thread
From: Wayne R. Roth @ 2016-01-19 18:37 UTC (permalink / raw)
  To: util-linux; +Cc: Wayne R. Roth

Logic copied from sys-utils/swapon.c

Signed-off-by: Wayne R. Roth <wayneroth42@gmail.com>
---
 disk-utils/mkswap.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index c559e60..2729596 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -344,7 +344,7 @@ static void write_header_to_device(struct mkswap_control *ctl)
 int main(int argc, char **argv)
 {
 	struct mkswap_control ctl = { .fd = -1 };
-	int c;
+	int c, permMask;
 	uint64_t sz;
 	int version = SWAP_VERSION;
 	char *block_count = NULL, *strsz = NULL;
@@ -464,6 +464,15 @@ int main(int argc, char **argv)
 			ctl.devname);
 
 	open_device(&ctl);
+        permMask = S_ISBLK(ctl.devstat.st_mode) ? 07007 : 07077;
+        if ((ctl.devstat.st_mode & permMask) != 0)
+                warnx(_("%s: insecure permissions %04o, %04o suggested."),
+                                ctl.devname, ctl.devstat.st_mode & 07777,
+                                ~permMask & 0666);
+        if (S_ISREG(ctl.devstat.st_mode) && ctl.devstat.st_uid != 0)
+                warnx(_("%s: insecure file owner %d, 0 (root) suggested."),
+                                ctl.devname, ctl.devstat.st_uid);
+
 
 	if (ctl.check)
 		check_blocks(&ctl);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2016-01-26 16:28 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-19 18:37 [PATCH] mkswap: Add warnings for insecure device permissions/owners Wayne R. Roth
2016-01-19 19:44 ` Mike Frysinger
2016-01-20  4:17   ` [PATCH] mkswap: Add warnings for insecure device permissions/owners Logic modified from sys-utils/swapon.c Wayne R. Roth
2016-01-20  4:58     ` Mike Frysinger
2016-01-20  6:09       ` [PATCH] mkswap: add " Wayne R. Roth
2016-01-26 10:35         ` Karel Zak
2016-01-20  9:39   ` [PATCH] mkswap: Add warnings for insecure device permissions/owners Sami Kerola
2016-01-20 10:30 ` Karel Zak
2016-01-21 22:19   ` Sarah Newman
2016-01-22 16:01     ` Tilman Schmidt
2016-01-22 19:14       ` Sarah Newman
2016-01-22 22:03         ` Sami Kerola
2016-01-23 16:22           ` Karel Zak
2016-01-24 11:09             ` Sami Kerola
2016-01-25 19:55               ` Sami Kerola
2016-01-26 10:42               ` Karel Zak
2016-01-26 16:28                 ` Sarah Newman
2016-01-25 21:39             ` Sarah Newman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox