linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] aio: add timeout validity check for io_[p]getevents
@ 2019-07-30  1:51 zhangyi (F)
  2019-07-30  7:11 ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: zhangyi (F) @ 2019-07-30  1:51 UTC (permalink / raw)
  To: linux-aio, linux-fsdevel, linux-kernel
  Cc: bcrl, viro, jmoyer, arnd, deepa.kernel, yi.zhang, wangkefeng.wang

io_[p]getevents syscall should return -EINVAL if timeout is out of
range, add this validity check.

Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: Jeff Moyer <jmoyer@redhat.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Deepa Dinamani <deepa.kernel@gmail.com>
---
Changes since v1:
 - add Reviewed-by and Cc tags.

 fs/aio.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 01e0fb9..dd967a0 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -2031,10 +2031,17 @@ static long do_io_getevents(aio_context_t ctx_id,
 		struct io_event __user *events,
 		struct timespec64 *ts)
 {
-	ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
-	struct kioctx *ioctx = lookup_ioctx(ctx_id);
+	ktime_t until = KTIME_MAX;
+	struct kioctx *ioctx = NULL;
 	long ret = -EINVAL;
 
+	if (ts) {
+		if (!timespec64_valid(ts))
+			return ret;
+		until = timespec64_to_ktime(*ts);
+	}
+
+	ioctx = lookup_ioctx(ctx_id);
 	if (likely(ioctx)) {
 		if (likely(min_nr <= nr && min_nr >= 0))
 			ret = read_events(ioctx, min_nr, nr, events, until);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] aio: add timeout validity check for io_[p]getevents
  2019-07-30  1:51 [PATCH v2] aio: add timeout validity check for io_[p]getevents zhangyi (F)
@ 2019-07-30  7:11 ` Arnd Bergmann
  2019-07-30 13:52   ` zhangyi (F)
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2019-07-30  7:11 UTC (permalink / raw)
  To: zhangyi (F)
  Cc: linux-aio, Linux FS-devel Mailing List,
	Linux Kernel Mailing List, Benjamin LaHaise, Al Viro, Jeff Moyer,
	Deepa Dinamani, Kefeng Wang

On Tue, Jul 30, 2019 at 3:46 AM zhangyi (F) <yi.zhang@huawei.com> wrote:

>  {
> -       ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
> -       struct kioctx *ioctx = lookup_ioctx(ctx_id);
> +       ktime_t until = KTIME_MAX;
> +       struct kioctx *ioctx = NULL;
>         long ret = -EINVAL;
>
> +       if (ts) {
> +               if (!timespec64_valid(ts))
> +                       return ret;
> +               until = timespec64_to_ktime(*ts);
> +       }

The man page should probably get updated as well to reflect that this
will now return -EINVAL for a negative timeout or malformed
nanoseconds.

      Arnd

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] aio: add timeout validity check for io_[p]getevents
  2019-07-30  7:11 ` Arnd Bergmann
@ 2019-07-30 13:52   ` zhangyi (F)
  0 siblings, 0 replies; 3+ messages in thread
From: zhangyi (F) @ 2019-07-30 13:52 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-aio, Linux FS-devel Mailing List,
	Linux Kernel Mailing List, Benjamin LaHaise, Al Viro, Jeff Moyer,
	Deepa Dinamani, Kefeng Wang

On 2019/7/30 15:11, Arnd Bergmann Wrote:
> On Tue, Jul 30, 2019 at 3:46 AM zhangyi (F) <yi.zhang@huawei.com> wrote:
> 
>>  {
>> -       ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
>> -       struct kioctx *ioctx = lookup_ioctx(ctx_id);
>> +       ktime_t until = KTIME_MAX;
>> +       struct kioctx *ioctx = NULL;
>>         long ret = -EINVAL;
>>
>> +       if (ts) {
>> +               if (!timespec64_valid(ts))
>> +                       return ret;
>> +               until = timespec64_to_ktime(*ts);
>> +       }
> 
> The man page should probably get updated as well to reflect that this
> will now return -EINVAL for a negative timeout or malformed
> nanoseconds.
> 

Thanks for your suggestion, I will add a patch to update the man page.

Thanks,
Yi.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-30 13:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30  1:51 [PATCH v2] aio: add timeout validity check for io_[p]getevents zhangyi (F)
2019-07-30  7:11 ` Arnd Bergmann
2019-07-30 13:52   ` zhangyi (F)

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).