Util-Linux package development
 help / color / mirror / Atom feed
From: "Wayne R. Roth" <wayneroth42@gmail.com>
To: util-linux@vger.kernel.org
Cc: "Wayne R. Roth" <wayneroth42@gmail.com>
Subject: [PATCH] mkswap: add warnings for insecure device permissions/owners Logic modified from sys-utils/swapon.c
Date: Tue, 19 Jan 2016 22:09:37 -0800	[thread overview]
Message-ID: <1453270177-19981-1-git-send-email-wayneroth42@gmail.com> (raw)
In-Reply-To: <20160120045857.GP14840@vapier.lan>

From: "Wayne R. Roth" <wayneroth42@gmail.com>

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..22999da 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 (getuid() == 0 && 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


  reply	other threads:[~2016-01-20  6:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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       ` Wayne R. Roth [this message]
2016-01-26 10:35         ` [PATCH] mkswap: add " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453270177-19981-1-git-send-email-wayneroth42@gmail.com \
    --to=wayneroth42@gmail.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox