Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4233744ybb; Tue, 7 Apr 2020 03:30:57 -0700 (PDT) X-Google-Smtp-Source: APiQypJKhhCJ8Reo2KwJB4JDZgVpX/xZbdWl3jYXZ7kockbqbY1oTLUXFAmwy6lDWULF+kEU3FlG X-Received: by 2002:aca:b1d4:: with SMTP id a203mr1146742oif.91.1586255457131; Tue, 07 Apr 2020 03:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586255457; cv=none; d=google.com; s=arc-20160816; b=WtsDqhW4sbZaMiEbIhXxEzhqF0naUmnf7fpdMroyiPb6gTVghQHGzafqbZmvOydXuF tdD5fKOVNvK68G+pQUB4fg98ejGbLo/v1zDytOBM9muTW5MsIvSCsJJ6zYr9qwFebe2Z +5PYuo9FpdWwPPjPEWjDaqzJouiDakl2nTtIV9VHkFZlTKP/+oSjT04uIIyf0f+bQCWt OnCx22ZA0v/yxxc8c+RY3pCIsjdb5eBRhl9zHuIvnGMm13TzaH1LUa+4Ub0/IKz7hoQV QAuLhAkKUjkDKwrhsfTgjzK31CGld8MGW5RYBA1UEKUKHtXP300pn+Il8/F85cxH1VuK VeBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YhuF4Anl4QHn8OWNNbqdl0GRzYVJAGtZmQH/0qQNgkM=; b=Hipe0vjoHox/04GdmCX/iY0Ey2YKmnhW1Fz1QiolxkSaelGWn5A2cYPOqRK3+rUJMm zyuqoyzWVtYLcdniRhrN5VmG/i1T2jR+nq0+wmncWAEfhaBamADx8swfMdAOEqhyMb2o kxYs2y5g4m1i6K9PygI0pAQs0J77mw/5ro25XLDUIgFjq5yJpUtRJ3PXoMZ15krXWMb6 76r/VWLOZ692UyViEmkNW21G+jqmCBB9qSMAJ+1W5Gi2LjvUQqgLdRYc53ES8S1Phqmb t9pzQLy7I7s06qqfbODtLyx3vKWgBKd3zrqHcRNTjrnlHmHSdukvy04BDJ6feYsHIjtP mGVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CLV8S4kK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si1001570ooo.92.2020.04.07.03.30.45; Tue, 07 Apr 2020 03:30:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CLV8S4kK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728395AbgDGK25 (ORCPT + 99 others); Tue, 7 Apr 2020 06:28:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:34964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728755AbgDGKYi (ORCPT ); Tue, 7 Apr 2020 06:24:38 -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 329B82082F; Tue, 7 Apr 2020 10:24:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586255077; bh=IefxS/Yc5ROgBysnlD7RBJzc6vlR8Ndpi0VarpK9QKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLV8S4kK7BRuHHhJPAfe68j6YzXoMOYt6pCHR9/t2l6wbNwzethD+anUKvS/6aT+R 1ysR60zEZ3RwtvZsCajx03P55wIdKCGaSDiXGug42pkxXLtTn4RnMv/nHmK8s7x9aX zp9/0nEKOHjsXDYmxYIzy/o3P6QSFTr1TnAlYfkQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bjorn Helgaas , Kees Cook , "Matthew Wilcox (Oracle)" , Sasha Levin Subject: [PATCH 5.5 20/46] XArray: Fix xa_find_next for large multi-index entries Date: Tue, 7 Apr 2020 12:21:51 +0200 Message-Id: <20200407101501.673089011@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200407101459.502593074@linuxfoundation.org> References: <20200407101459.502593074@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 From: Matthew Wilcox (Oracle) [ Upstream commit bd40b17ca49d7d110adf456e647701ce74de2241 ] Coverity pointed out that xas_sibling() was shifting xa_offset without promoting it to an unsigned long first, so the shift could cause an overflow and we'd get the wrong answer. The fix is obvious, and the new test-case provokes UBSAN to report an error: runtime error: shift exponent 60 is too large for 32-bit type 'int' Fixes: 19c30f4dd092 ("XArray: Fix xa_find_after with multi-index entries") Reported-by: Bjorn Helgaas Reported-by: Kees Cook Signed-off-by: Matthew Wilcox (Oracle) Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin --- lib/test_xarray.c | 18 ++++++++++++++++++ lib/xarray.c | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/test_xarray.c b/lib/test_xarray.c index 55c14e8c88591..8c7d7a8468b88 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -12,6 +12,9 @@ static unsigned int tests_run; static unsigned int tests_passed; +static const unsigned int order_limit = + IS_ENABLED(CONFIG_XARRAY_MULTI) ? BITS_PER_LONG : 1; + #ifndef XA_DEBUG # ifdef __KERNEL__ void xa_dump(const struct xarray *xa) { } @@ -959,6 +962,20 @@ static noinline void check_multi_find_2(struct xarray *xa) } } +static noinline void check_multi_find_3(struct xarray *xa) +{ + unsigned int order; + + for (order = 5; order < order_limit; order++) { + unsigned long index = 1UL << (order - 5); + + XA_BUG_ON(xa, !xa_empty(xa)); + xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL); + XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT)); + xa_erase_index(xa, 0); + } +} + static noinline void check_find_1(struct xarray *xa) { unsigned long i, j, k; @@ -1081,6 +1098,7 @@ static noinline void check_find(struct xarray *xa) for (i = 2; i < 10; i++) check_multi_find_1(xa, i); check_multi_find_2(xa); + check_multi_find_3(xa); } /* See find_swap_entry() in mm/shmem.c */ diff --git a/lib/xarray.c b/lib/xarray.c index 1d9fab7db8dad..acd1fad2e862a 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1839,7 +1839,8 @@ static bool xas_sibling(struct xa_state *xas) if (!node) return false; mask = (XA_CHUNK_SIZE << node->shift) - 1; - return (xas->xa_index & mask) > (xas->xa_offset << node->shift); + return (xas->xa_index & mask) > + ((unsigned long)xas->xa_offset << node->shift); } /** -- 2.20.1