[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140418162930.GC12515@htj.dyndns.org>
Date: Fri, 18 Apr 2014 12:29:30 -0400
From: Tejun Heo <tj@...nel.org>
To: Lai Jiangshan <laijs@...fujitsu.com>
Cc: linux-kernel@...r.kernel.org, stable@...r.kernel.org,
Andrew Morton <akpm@...ux-foundation.org>,
Jean Delvare <jdelvare@...e.de>,
Monam Agarwal <monamagarwal123@...il.com>,
Jeff Layton <jlayton@...hat.com>,
Andreas Gruenbacher <agruen@...bit.com>,
Stephen Hemminger <stephen@...workplumber.org>
Subject: Re: [PATCH 1/8] idr: fix overflow bug for the max-high layer
Hello,
Subject: idr: fix overflow bug during maximum ID calculation at maximum height
On Fri, Apr 18, 2014 at 08:49:48PM +0800, Lai Jiangshan wrote:
> In idr_replace(), when the top layer is the max-high layer(p->layer == 3),
> The "(1 << n)" will overflow and the result is 0, it causes idr_replace()
> return -EINVAL even the id is actually valid.
idr_replace() open-codes the logic to calculate the maximum valid ID
given the height of the idr tree; unfortunately, the open-coded logic
doesn't account for the fact that the top layer may have unused slots
and over-shifts the limit to zero when the tree is at its maximum
height.
> The following test code shows it fails to replace the value for id=((1<<27)+42):
>
> static void test5(void)
> {
> int id;
> DEFINE_IDR(test_idr);
> #define TEST5_START ((1<<27)+42) /* use the highest layer */
>
> printk(KERN_INFO "Start test5\n");
> id = idr_alloc(&test_idr, (void *)1, TEST5_START, 0, GFP_KERNEL);
> BUG_ON(id != TEST5_START);
> TEST_BUG_ON(idr_replace(&test_idr, (void *)2, TEST5_START) != (void *)1);
> idr_destroy(&test_idr);
> printk(KERN_INFO "End of test5\n");
> }
>
> Fixed the bug by using idr_max() instead of the incorrect open code.
Fix the bug by using idr_max() which correctly takes into account the
maximum allowed shift.
> There is the same problem in sub_alloc(). The overflow causes sub_alloc()
> returns -EAGAIN unexpectedly. But the idr_get_empty_slot() will call it
> again with increased @id. So the bug is hided.
sub_alloc() shares the same problem and may incorrectly fail with
-EAGAIN; however, this bug doesn't affect correct operation because
idr_get_empty_slot(), which already uses idr_max(), retries with the
increased @id in such cases.
> CC: stable@...r.kernel.org
> Signed-off-by: Lai Jiangshan <laijs@...fujitsu.com>
Acked-by: Tejun Heo <tj@...nel.org>
Thanks.
--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists