* [PATCH] Monitor: don't use default modes when creating a file
@ 2020-11-24 15:41 Mariusz Tkaczyk
2020-11-25 23:09 ` Jes Sorensen
0 siblings, 1 reply; 2+ messages in thread
From: Mariusz Tkaczyk @ 2020-11-24 15:41 UTC (permalink / raw)
To: jes; +Cc: linux-raid
Replace fopen() calls by open() with creation mode directly specified.
This fixes the potential security issue. Use octal values instead masks.
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
Monitor.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/Monitor.c b/Monitor.c
index 7fd4808..a82e99d 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -305,8 +305,11 @@ static int make_daemon(char *pidfile)
if (!pidfile)
printf("%d\n", pid);
else {
- FILE *pid_file;
- pid_file=fopen(pidfile, "w");
+ FILE *pid_file = NULL;
+ int fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC,
+ 0644);
+ if (fd >= 0)
+ pid_file = fdopen(fd, "w");
if (!pid_file)
perror("cannot create pid file");
else {
@@ -368,13 +371,17 @@ static void write_autorebuild_pid()
{
char path[PATH_MAX];
int pid;
- FILE *fp;
+ FILE *fp = NULL;
sprintf(path, "%s/autorebuild.pid", MDMON_DIR);
- if (mkdir(MDMON_DIR, S_IRWXU) < 0 && errno != EEXIST) {
+ if (mkdir(MDMON_DIR, 0700) < 0 && errno != EEXIST) {
pr_err("Can't create autorebuild.pid file\n");
} else {
- fp = fopen(path, "w");
+ int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0700);
+
+ if (fd >= 0)
+ fp = fdopen(fd, "w");
+
if (!fp)
pr_err("Can't create autorebuild.pid file\n");
else {
--
2.25.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Monitor: don't use default modes when creating a file
2020-11-24 15:41 [PATCH] Monitor: don't use default modes when creating a file Mariusz Tkaczyk
@ 2020-11-25 23:09 ` Jes Sorensen
0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2020-11-25 23:09 UTC (permalink / raw)
To: Mariusz Tkaczyk; +Cc: linux-raid
On 11/24/20 10:41 AM, Mariusz Tkaczyk wrote:
> Replace fopen() calls by open() with creation mode directly specified.
> This fixes the potential security issue. Use octal values instead masks.
>
> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
> ---
> Monitor.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
Applied!
Thanks,
Jes
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-25 23:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-24 15:41 [PATCH] Monitor: don't use default modes when creating a file Mariusz Tkaczyk
2020-11-25 23:09 ` Jes Sorensen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.