linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Fix int overflow in callers of do_shrink_slab()
@ 2018-09-28 11:28 Kirill Tkhai
  2018-09-28 11:34 ` Cyrill Gorcunov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kirill Tkhai @ 2018-09-28 11:28 UTC (permalink / raw)
  To: akpm, gorcunov, ktkhai, mhocko, aryabinin, hannes,
	penguin-kernel, shakeelb, jbacik, linux-mm, linux-kernel

do_shrink_slab() returns unsigned long value, and
the placing into int variable cuts high bytes off.
Then we compare ret and 0xfffffffe (since SHRINK_EMPTY
is converted to ret type).

Thus, big number of objects returned by do_shrink_slab()
may be interpreted as SHRINK_EMPTY, if low bytes of
their value are equal to 0xfffffffe. Fix that
by declaration ret as unsigned long in these functions.

Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 mm/vmscan.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 0b63d9a2dc17..8ea87586925e 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -581,8 +581,8 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid,
 			struct mem_cgroup *memcg, int priority)
 {
 	struct memcg_shrinker_map *map;
-	unsigned long freed = 0;
-	int ret, i;
+	unsigned long ret, freed = 0;
+	int i;
 
 	if (!memcg_kmem_enabled() || !mem_cgroup_online(memcg))
 		return 0;
@@ -678,9 +678,8 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
 				 struct mem_cgroup *memcg,
 				 int priority)
 {
+	unsigned long ret, freed = 0;
 	struct shrinker *shrinker;
-	unsigned long freed = 0;
-	int ret;
 
 	if (!mem_cgroup_is_root(memcg))
 		return shrink_slab_memcg(gfp_mask, nid, memcg, priority);


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

* Re: [PATCH] mm: Fix int overflow in callers of do_shrink_slab()
  2018-09-28 11:28 [PATCH] mm: Fix int overflow in callers of do_shrink_slab() Kirill Tkhai
@ 2018-09-28 11:34 ` Cyrill Gorcunov
  2018-09-28 11:35 ` Josef Bacik
  2018-09-28 21:15 ` Andrew Morton
  2 siblings, 0 replies; 6+ messages in thread
From: Cyrill Gorcunov @ 2018-09-28 11:34 UTC (permalink / raw)
  To: Kirill Tkhai
  Cc: akpm, mhocko, aryabinin, hannes, penguin-kernel, shakeelb,
	jbacik, linux-mm, linux-kernel

On Fri, Sep 28, 2018 at 02:28:32PM +0300, Kirill Tkhai wrote:
> do_shrink_slab() returns unsigned long value, and
> the placing into int variable cuts high bytes off.
> Then we compare ret and 0xfffffffe (since SHRINK_EMPTY
> is converted to ret type).
> 
> Thus, big number of objects returned by do_shrink_slab()
> may be interpreted as SHRINK_EMPTY, if low bytes of
> their value are equal to 0xfffffffe. Fix that
> by declaration ret as unsigned long in these functions.
> 
> Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>

Thank you!

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

* Re: [PATCH] mm: Fix int overflow in callers of do_shrink_slab()
  2018-09-28 11:28 [PATCH] mm: Fix int overflow in callers of do_shrink_slab() Kirill Tkhai
  2018-09-28 11:34 ` Cyrill Gorcunov
@ 2018-09-28 11:35 ` Josef Bacik
  2018-09-28 21:15 ` Andrew Morton
  2 siblings, 0 replies; 6+ messages in thread
From: Josef Bacik @ 2018-09-28 11:35 UTC (permalink / raw)
  To: Kirill Tkhai
  Cc: akpm, gorcunov, mhocko, aryabinin, hannes, penguin-kernel,
	shakeelb, jbacik, linux-mm, linux-kernel

On Fri, Sep 28, 2018 at 02:28:32PM +0300, Kirill Tkhai wrote:
> do_shrink_slab() returns unsigned long value, and
> the placing into int variable cuts high bytes off.
> Then we compare ret and 0xfffffffe (since SHRINK_EMPTY
> is converted to ret type).
> 
> Thus, big number of objects returned by do_shrink_slab()
> may be interpreted as SHRINK_EMPTY, if low bytes of
> their value are equal to 0xfffffffe. Fix that
> by declaration ret as unsigned long in these functions.
> 
> Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef

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

* Re: [PATCH] mm: Fix int overflow in callers of do_shrink_slab()
  2018-09-28 11:28 [PATCH] mm: Fix int overflow in callers of do_shrink_slab() Kirill Tkhai
  2018-09-28 11:34 ` Cyrill Gorcunov
  2018-09-28 11:35 ` Josef Bacik
@ 2018-09-28 21:15 ` Andrew Morton
  2018-09-28 21:21   ` Cyrill Gorcunov
  2018-09-28 23:58   ` Kirill Tkhai
  2 siblings, 2 replies; 6+ messages in thread
From: Andrew Morton @ 2018-09-28 21:15 UTC (permalink / raw)
  To: Kirill Tkhai
  Cc: gorcunov, mhocko, aryabinin, hannes, penguin-kernel, shakeelb,
	jbacik, linux-mm, linux-kernel

On Fri, 28 Sep 2018 14:28:32 +0300 Kirill Tkhai <ktkhai@virtuozzo.com> wrote:

> do_shrink_slab() returns unsigned long value, and
> the placing into int variable cuts high bytes off.
> Then we compare ret and 0xfffffffe (since SHRINK_EMPTY
> is converted to ret type).
> 
> Thus, big number of objects returned by do_shrink_slab()
> may be interpreted as SHRINK_EMPTY, if low bytes of
> their value are equal to 0xfffffffe. Fix that
> by declaration ret as unsigned long in these functions.

Sigh.  How many times has this happened.

> Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>

What did he report?  Was it code inspection?  Did the kernel explode? 
etcetera.  I'm thinking that the fix should be backported but to
determine that, we need to understand the end-user runtime effects, as
always.  Please.


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

* Re: [PATCH] mm: Fix int overflow in callers of do_shrink_slab()
  2018-09-28 21:15 ` Andrew Morton
@ 2018-09-28 21:21   ` Cyrill Gorcunov
  2018-09-28 23:58   ` Kirill Tkhai
  1 sibling, 0 replies; 6+ messages in thread
From: Cyrill Gorcunov @ 2018-09-28 21:21 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kirill Tkhai, mhocko, aryabinin, hannes, penguin-kernel,
	shakeelb, jbacik, linux-mm, linux-kernel

On Fri, Sep 28, 2018 at 02:15:09PM -0700, Andrew Morton wrote:
> What did he report?  Was it code inspection?  Did the kernel explode? 
> etcetera.  I'm thinking that the fix should be backported but to
> determine that, we need to understand the end-user runtime effects, as
> always.  Please.

I've been investigating unrelated but and occasionally found this nit.
Look, there should be over 4G of objects scanned to have it triggered,
so I don't expect it happen in real life but better be on a safe side
and fix it.

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

* Re: [PATCH] mm: Fix int overflow in callers of do_shrink_slab()
  2018-09-28 21:15 ` Andrew Morton
  2018-09-28 21:21   ` Cyrill Gorcunov
@ 2018-09-28 23:58   ` Kirill Tkhai
  1 sibling, 0 replies; 6+ messages in thread
From: Kirill Tkhai @ 2018-09-28 23:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: gorcunov, mhocko, aryabinin, hannes, penguin-kernel, shakeelb,
	jbacik, linux-mm, linux-kernel

On 29.09.2018 00:15, Andrew Morton wrote:
> On Fri, 28 Sep 2018 14:28:32 +0300 Kirill Tkhai <ktkhai@virtuozzo.com> wrote:
> 
>> do_shrink_slab() returns unsigned long value, and
>> the placing into int variable cuts high bytes off.
>> Then we compare ret and 0xfffffffe (since SHRINK_EMPTY
>> is converted to ret type).
>>
>> Thus, big number of objects returned by do_shrink_slab()
>> may be interpreted as SHRINK_EMPTY, if low bytes of
>> their value are equal to 0xfffffffe. Fix that
>> by declaration ret as unsigned long in these functions.
> 
> Sigh.  How many times has this happened.
> 
>> Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>
> 
> What did he report?  Was it code inspection?  Did the kernel explode? 
> etcetera.  I'm thinking that the fix should be backported but to
> determine that, we need to understand the end-user runtime effects, as
> always.  Please.

Yeah, it was just code inspection. It's need to be a really unlucky person
to meet this in real life -- the probability is very small.

The runtime effect would be the following. Such the unlucky person would
have a single shrinker, which is never called for a single memory cgroup,
despite there are objects charged.

Thanks,
Kirill

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

end of thread, other threads:[~2018-09-28 23:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-28 11:28 [PATCH] mm: Fix int overflow in callers of do_shrink_slab() Kirill Tkhai
2018-09-28 11:34 ` Cyrill Gorcunov
2018-09-28 11:35 ` Josef Bacik
2018-09-28 21:15 ` Andrew Morton
2018-09-28 21:21   ` Cyrill Gorcunov
2018-09-28 23:58   ` Kirill Tkhai

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