From: Carlos Maiolino <cmaiolino@redhat.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH] xfs_io: prevents the usage in FIFO files
Date: Tue, 16 Oct 2018 11:43:43 +0200 [thread overview]
Message-ID: <20181016094343.21102-1-cmaiolino@redhat.com> (raw)
Recently we had a bug report of xfs_io frozen on a file, which ended up
being a pipe, and xfs_io was waiting for data on the other side of the
pipe.
Although xfs_io was not stuck due a bug itself, we can do better and
check the file type before opening the file. xfs_io has very limited
usage on pipes, so, just check and deny opening of FIFO files.
Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
I belive having a generic helper to check the file type may have other uses too,
so I opted to make it a generic helper.
include/libfrog.h | 2 ++
io/open.c | 6 ++++++
libfrog/util.c | 12 ++++++++++++
3 files changed, 20 insertions(+)
diff --git a/include/libfrog.h b/include/libfrog.h
index d33f0146..693d026d 100644
--- a/include/libfrog.h
+++ b/include/libfrog.h
@@ -5,7 +5,9 @@
*/
#ifndef __LIBFROG_UTIL_H_
#define __LIBFROG_UTIL_H_
+#include <sys/types.h>
unsigned int log2_roundup(unsigned int i);
+unsigned int check_file_type(char *name, mode_t mode);
#endif /* __LIBFROG_UTIL_H_ */
diff --git a/io/open.c b/io/open.c
index 6ea3e9a2..25f44b64 100644
--- a/io/open.c
+++ b/io/open.c
@@ -9,6 +9,7 @@
#include "init.h"
#include "io.h"
#include "libxfs.h"
+#include "libfrog.h"
#ifndef __O_TMPFILE
#if defined __alpha__
@@ -59,6 +60,11 @@ openfile(
int fd;
int oflags;
+ if (check_file_type(path, S_IFIFO)) {
+ fprintf(stderr, _("xfs_io does not work on FIFO files\n"));
+ return -1;
+ }
+
oflags = flags & IO_READONLY ? O_RDONLY : O_RDWR;
if (flags & IO_APPEND)
oflags |= O_APPEND;
diff --git a/libfrog/util.c b/libfrog/util.c
index ff935184..de0b8542 100644
--- a/libfrog/util.c
+++ b/libfrog/util.c
@@ -5,6 +5,9 @@
*/
#include "platform_defs.h"
#include "libfrog.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
/*
* libfrog is a collection of miscellaneous userspace utilities.
@@ -22,3 +25,12 @@ log2_roundup(unsigned int i)
}
return rval;
}
+
+unsigned int
+check_file_type(char *name, mode_t mode)
+{
+ struct stat sb;
+
+ lstat(name, &sb);
+ return (sb.st_mode & mode);
+}
--
2.17.1
next reply other threads:[~2018-10-16 17:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-16 9:43 Carlos Maiolino [this message]
2018-11-01 15:41 ` [PATCH] xfs_io: prevents the usage in FIFO files Eric Sandeen
2018-11-01 16:32 ` Darrick J. Wong
2018-11-02 13:11 ` Carlos Maiolino
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=20181016094343.21102-1-cmaiolino@redhat.com \
--to=cmaiolino@redhat.com \
--cc=linux-xfs@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;
as well as URLs for NNTP newsgroup(s).