All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Monakhov <dmonakhov@openvz.org>
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk,
	Dmitry Monakhov <dmonakhov@openvz.org>
Subject: [PATCH 15/16] pipe: use is_xxx_kiocb instead of filp->fl_flags
Date: Sat,  4 Apr 2015 23:13:24 +0400	[thread overview]
Message-ID: <1428174805-853-16-git-send-email-dmonakhov@openvz.org> (raw)
In-Reply-To: <1428174805-853-1-git-send-email-dmonakhov@openvz.org>

Also fix other long standing issues caused by fcntl(,F_SETFL,):
- One can disable O_DIRECT for pipe[1] (paketized IO), but can not enable it again.
- Currently we do not set O_APPEND on pipe[1] (IMHO it is wrong, but let it be)
  so it is reasonable to completely prohibit change O_APPEND flag on both
  end's of pipe. Add ->check_flags method in order to diallow O_APPEND toggling.

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 fs/fcntl.c |    6 ++++--
 fs/pipe.c  |   20 +++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/fs/fcntl.c b/fs/fcntl.c
index ee85cd4..0bdc9c7 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -51,9 +51,11 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
 	       if (arg & O_NDELAY)
 		   arg |= O_NONBLOCK;
 
+	/* allowed only for inodes with ->direct_io method or write pipe */
 	if (arg & O_DIRECT) {
-		if (!filp->f_mapping || !filp->f_mapping->a_ops ||
-			!filp->f_mapping->a_ops->direct_IO)
+		if ((!filp->f_mapping || !filp->f_mapping->a_ops ||
+		     !filp->f_mapping->a_ops->direct_IO) &&
+		    !(get_pipe_info(filp) && (filp->f_flags | O_WRONLY)))
 				return -EINVAL;
 	}
 
diff --git a/fs/pipe.c b/fs/pipe.c
index 2d084f2..95b5fe4 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -301,7 +301,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
 			 */
 			if (ret)
 				break;
-			if (filp->f_flags & O_NONBLOCK) {
+			if (is_nonblock_kiocb(iocb)) {
 				ret = -EAGAIN;
 				break;
 			}
@@ -329,9 +329,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
 	return ret;
 }
 
-static inline int is_packetized(struct file *file)
+static inline int is_packetized(struct kiocb *kiocb)
 {
-	return (file->f_flags & O_DIRECT) != 0;
+	return is_direct_kiocb(kiocb);
 }
 
 static ssize_t
@@ -427,7 +427,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
 			buf->offset = 0;
 			buf->len = copied;
 			buf->flags = 0;
-			if (is_packetized(filp)) {
+			if (is_packetized(iocb)) {
 				buf->ops = &packet_pipe_buf_ops;
 				buf->flags = PIPE_BUF_FLAG_PACKET;
 			}
@@ -439,7 +439,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
 		}
 		if (bufs < pipe->buffers)
 			continue;
-		if (filp->f_flags & O_NONBLOCK) {
+		if (is_nonblock_kiocb(iocb)) {
 			if (!ret)
 				ret = -EAGAIN;
 			break;
@@ -943,6 +943,15 @@ err:
 	return ret;
 }
 
+/* XXX: Currently it is not possible distinguish read side from write one */
+static int pipe_check_flags(int flags)
+{
+	if (flags & O_APPEND)
+	    return -EINVAL;
+
+	return 0;
+}
+
 const struct file_operations pipefifo_fops = {
 	.open		= fifo_open,
 	.llseek		= no_llseek,
@@ -954,6 +963,7 @@ const struct file_operations pipefifo_fops = {
 	.unlocked_ioctl	= pipe_ioctl,
 	.release	= pipe_release,
 	.fasync		= pipe_fasync,
+	.check_flags	= pipe_check_flags,
 };
 
 /*
-- 
1.7.1


  parent reply	other threads:[~2015-04-04 19:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-04 19:13 [PATCH 00/16] fs: fixup racy check file->f_flags for xxx_write_iter Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 01/16] fs: save file->f_flags to kiocb->ki_flags Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 02/16] vfs: check kiocb->ki_flags instead filp->fl_flags Dmitry Monakhov
2015-04-04 21:36   ` Al Viro
2015-04-05 11:03     ` Dmitry Monakhov
2015-04-05 18:11       ` Al Viro
2015-04-05 21:54         ` Al Viro
2015-04-04 19:13 ` [PATCH 03/16] ext4: use is_xxx_kiocb instead of filp->fl_flags Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 04/16] 9p: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 05/16] btrfs: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 06/16] ceph: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 07/16] cifs: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 08/16] gfs2: " Dmitry Monakhov
2015-04-04 19:13   ` [Cluster-devel] " Dmitry Monakhov
2015-04-07 13:11   ` Steven Whitehouse
2015-04-07 13:11     ` Steven Whitehouse
2015-04-04 19:13 ` [PATCH 09/16] nfs: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 10/16] ntfs: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 11/16] ocfs2: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 12/16] udf: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 13/16] xfs: " Dmitry Monakhov
2015-04-04 19:13 ` [PATCH 14/16] fuse: " Dmitry Monakhov
2015-04-04 19:13 ` Dmitry Monakhov [this message]
2015-04-04 19:13 ` [PATCH 16/16] splice: fix race beween splice_write vs fcntl(,F_SETFL,) Dmitry Monakhov

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=1428174805-853-16-git-send-email-dmonakhov@openvz.org \
    --to=dmonakhov@openvz.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 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.