linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Joel Becker <jlbec@evilplan.org>,
	linux-kernel@vger.kernel.org,
	Bodo Stroesser <bostroesser@gmail.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Yanko Kaneti <yaneti@declera.com>,
	Brendan Higgins <brendanhiggins@google.com>,
	Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH 1/4] configfs: Rework the overflow check in fill_write_buffer()
Date: Fri, 23 Jul 2021 14:23:50 -0700	[thread overview]
Message-ID: <20210723212353.896343-2-bvanassche@acm.org> (raw)
In-Reply-To: <20210723212353.896343-1-bvanassche@acm.org>

Change 'if (SIMPLE_ATTR_SIZE - 1 - pos <= 0)' into
'if (pos >= SIMPLE_ATTR_SIZE - 1)'. Change the data type of 'to_copy'
from long long (loff_t) into int. Do not check whether pos < 0 since
rw_verify_area() checks this for us. As one can see on
https://lore.kernel.org/lkml/CAHk-=wjuDBQdUvaO=XaptgmvE_qeg_EuZjsUZf2vVoXPUMgAvg@mail.gmail.com/
these changes have been requested by Linus Torvalds.

Cc: Bodo Stroesser <bostroesser@gmail.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Yanko Kaneti <yaneti@declera.com>
Cc: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 fs/configfs/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 5a0be9985bae..8121bb1b2121 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -181,8 +181,7 @@ static ssize_t configfs_bin_read_iter(struct kiocb *iocb, struct iov_iter *to)
 static int fill_write_buffer(struct configfs_buffer *buffer, loff_t pos,
 			     struct iov_iter *from)
 {
-	loff_t to_copy;
-	int copied;
+	int to_copy, copied;
 	u8 *to;
 
 	if (!buffer->page)
@@ -190,9 +189,9 @@ static int fill_write_buffer(struct configfs_buffer *buffer, loff_t pos,
 	if (!buffer->page)
 		return -ENOMEM;
 
-	to_copy = SIMPLE_ATTR_SIZE - 1 - pos;
-	if (to_copy <= 0)
+	if (pos >= SIMPLE_ATTR_SIZE - 1)
 		return 0;
+	to_copy = SIMPLE_ATTR_SIZE - 1 - pos;
 	to = buffer->page + pos;
 	copied = copy_from_iter(to, to_copy, from);
 	buffer->needs_read_fill = 1;

  reply	other threads:[~2021-07-23 21:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23 21:23 [PATCH 0/4] Improve the configfs read and write iterators further Bart Van Assche
2021-07-23 21:23 ` Bart Van Assche [this message]
2021-07-23 21:23 ` [PATCH 2/4] configfs: Fix writing at a non-zero offset Bart Van Assche
2021-07-26 14:58   ` Bodo Stroesser
2021-07-26 16:26     ` Bart Van Assche
2021-07-26 21:13       ` Bodo Stroesser
2021-07-26 21:52         ` Bart Van Assche
2021-07-27  0:54           ` Bodo Stroesser
2021-07-27  3:17             ` Bart Van Assche
2021-07-27  7:27               ` Bodo Stroesser
2021-07-27 16:47                 ` Bart Van Assche
2021-07-28 17:14                   ` Bodo Stroesser
2021-07-28 17:55                     ` Bart Van Assche
2021-07-23 21:23 ` [PATCH 3/4] kunit: Add support for suite initialization and cleanup Bart Van Assche
2021-07-27 21:26   ` Brendan Higgins
2021-07-29  3:33     ` Bart Van Assche
2021-07-23 21:23 ` [PATCH 4/4] configfs: Add unit tests Bart Van Assche

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=20210723212353.896343-2-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=bostroesser@gmail.com \
    --cc=brendanhiggins@google.com \
    --cc=hch@lst.de \
    --cc=jlbec@evilplan.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=yaneti@declera.com \
    /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).