From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFD78C31E45 for ; Thu, 13 Jun 2019 16:23:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 86F0920644 for ; Thu, 13 Jun 2019 16:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560443005; bh=X+R5vzI3sP3DJBHPZdTdhePeFCbETwqSZUEN09NkQjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=vgm6EtBi/BFxqWUCOGK59Ey6TzXXqEruhiaoK6yoe5GkdqtokU2MGUSlHEYnizIBV nIAd1QPgpKb2sLyrFWkrRrgMkAJbNX2iX4c6l8gisT1BwgRUjj74R7Pu+2Skr3uDx4 BIOo2zPsDw4ws3GN4ezHGvN8MRN374yb9RzrOfaA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391478AbfFMQXD (ORCPT ); Thu, 13 Jun 2019 12:23:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:55420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731034AbfFMIh7 (ORCPT ); Thu, 13 Jun 2019 04:37:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AC89C21473; Thu, 13 Jun 2019 08:37:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560415078; bh=X+R5vzI3sP3DJBHPZdTdhePeFCbETwqSZUEN09NkQjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HCDCczUYgm6G+WxEidmZKZqp97q9ZIqXtIatdAeICyHm4jb+VRqSeCU7ZxGhiOQvb BjzEEQijYQ6J7mJCF+A+nvr/XGWVp7eZ+rvrop53dm+xxulUOb1wg75oInEPiFiWcs Itgy6CC3TaSkMgAFhski253d1KxhbbZhFo6ANdzY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dennis Zhou , Peng Fan , Sasha Levin Subject: [PATCH 4.14 78/81] percpu: do not search past bitmap when allocating an area Date: Thu, 13 Jun 2019 10:34:01 +0200 Message-Id: <20190613075654.739666493@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190613075649.074682929@linuxfoundation.org> References: <20190613075649.074682929@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 8c43004af01635cc9fbb11031d070e5e0d327ef2 ] pcpu_find_block_fit() guarantees that a fit is found within PCPU_BITMAP_BLOCK_BITS. Iteration is used to determine the first fit as it compares against the block's contig_hint. This can lead to incorrectly scanning past the end of the bitmap. The behavior was okay given the check after for bit_off >= end and the correctness of the hints from pcpu_find_block_fit(). This patch fixes this by bounding the end offset by the number of bits in a chunk. Signed-off-by: Dennis Zhou Reviewed-by: Peng Fan Signed-off-by: Sasha Levin --- mm/percpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/percpu.c b/mm/percpu.c index bc58bcbe4b60..9beb84800d8d 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -984,7 +984,8 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int alloc_bits, /* * Search to find a fit. */ - end = start + alloc_bits + PCPU_BITMAP_BLOCK_BITS; + end = min_t(int, start + alloc_bits + PCPU_BITMAP_BLOCK_BITS, + pcpu_chunk_map_bits(chunk)); bit_off = bitmap_find_next_zero_area(chunk->alloc_map, end, start, alloc_bits, align_mask); if (bit_off >= end) -- 2.20.1