lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0a8f34aa-ced9-e613-3e5f-b5e53a3ef3d9@huaweicloud.com>
Date:   Sat, 7 Oct 2023 09:23:58 +0800
From:   Yu Kuai <yukuai1@...weicloud.com>
To:     Oleg Nesterov <oleg@...hat.com>, Li Nan <linan666@...weicloud.com>
Cc:     Khazhy Kumykov <khazhy@...omium.org>, tj@...nel.org,
        josef@...icpanda.com, axboe@...nel.dk, cgroups@...r.kernel.org,
        linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
        yi.zhang@...wei.com, houtao1@...wei.com, yangerkun@...wei.com,
        "yukuai (C)" <yukuai3@...wei.com>
Subject: Re: [PATCH] blk-throttle: Calculate allowed value only when the
 throttle is enabled

Hi,

在 2023/10/06 0:24, Oleg Nesterov 写道:
> Hi Li,
> 
> On 10/05, Li Nan wrote:
>>
>>> I don't think this change is sufficient to prevent kernel crash, as a
>>> "clever" user could still set the bps_limit to U64_MAX - 1 (or another
>>> large value), which probably would still result in the same crash. The
>>> comment in mul_u64_u64_div_u64 suggests there's something we can do to
>>> better handle the overflow case, but I'm not sure what it's referring
>>> to. ("Will generate an #DE when the result doesn't fit u64, could fix
>>> with an __ex_table[] entry when it becomes an issue.") Otherwise, we
>>
>> When (a * mul) overflows, a divide 0 error occurs in
>> mul_u64_u64_div_u64(). Commit 3dc167ba5729 ("sched/cputime: Improve
>> cputime_adjust()") changed func and said: "Will generate an #DE when the
>> result doesn't fit u64, could fix with an __ex_table[] entry when it
>> becomes an issue." But we are unsure of how to fix it. Could you please
>> explain how to fix this issue.
> 
> Not sure I understand the question...
> 
> OK, we can change mul_u64_u64_div_u64() to trap the exception, say,
> 
> 	static inline u64 mul_u64_u64_div_u64(u64 a, u64 mul, u64 div)
> 	{
> 		u64 q;
> 
> 		asm ("mulq %2; 1: divq %3; 2:\n"
> 		     _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_DEFAULT|EX_FLAG_CLEAR_AX)
> 					: "=a" (q)
> 					: "a" (a), "rm" (mul), "rm" (div)
> 					: "rdx");
> 
> 		return q;
> 	}
> 
> should (iiuc) return 0 if the result doesn't fit u64 or div == 0.
> 
> But even if we forget that this is x86-specific, how can this help?
> What should calculate_bytes_allowed() do/return in this case?

I believe, U64_MAX should be returned if result doesn't fit u64;
> 
>>> probably need to remove the mul_u64_u64_div_u64 and check for
>>> overflow/potential overflow ourselves?
> 
> probably yes...

How about this?

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 1101fb6f6cc8..5482c316a103 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -723,6 +723,10 @@ static unsigned int calculate_io_allowed(u32 
iops_limit,

  static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long 
jiffy_elapsed)
  {
+       if (jiffy_elapsed > HZ &&
+           bps_limit > mul_u64_u64_div_u64(U64_MAX, (u64)HZ, 
(u64)jiffy_elapsed);
+               return U64_MAX;
+
         return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
  }

> 
> Oleg.
> 
> .
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ