Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5236076ybl; Tue, 27 Aug 2019 01:17:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqy0qIMKcJpJZOx+HeJLhoJIdaUPfAhQGxVP1OEIf0KRvAaDF03cupNvB1hiEnonD62Frhqc X-Received: by 2002:a63:2bd2:: with SMTP id r201mr19796529pgr.193.1566893867767; Tue, 27 Aug 2019 01:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893867; cv=none; d=google.com; s=arc-20160816; b=ZTatWV7eX6V1MDgjvyrcmDUuou+WOgh2ai1KkmsV3jugw85g9HzGrPVw26udBR7V0h zOv/enVXcgXu8FVk6DZ4Ucs5P1Y7h4jMimVdTud9Tf69EQQhGlzdQoFBEGKtKxpxGu5t SG9OgLFgqrg3WMZ19G2R2RLnYDQOmtmZdpbXFHuAQEkPO5v4lhFqykdMdtO3lTDsUZ/b gGhE+Rb9SmXsjPgtj3+LHTA3y+XGSeOG6nFZqkdZIRp2lQYIE4cvM0Y/uiC9bHoGFRQK xuy/Nwo0btjCSd90mc+KG97RdTilyfkRa8sCNGwtVTSCEO3Sgn+lzE0zO2jtUupiW4uU +dcQ== 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=g17iSFWpjNKb8bnOlcXb4NxRl4xFb0zZEYB5FNWH6m4=; b=Vbz/W0oXrcpA0HCzHtGaBNcA0rnPPOhPbOGO0Gzk17qxqNO5GIZBKw+Zh+NQEDPZWK SehvMd6wW1JP9PathE8X//f+G71X1X8BdWmuVAByA1H59wcwNQAtjNwv1XthgdCa07YG ERmQ41CUl/yvz1qZRyqwKsOu6bKxWEhnPw4uZaYgc/8cPRLxD9dTAtdfb2M+uFDIOZMx b6k72REmCzh4kJ8PgTtNpy07zDQwei2dUe2tdOsCBmfWxn22Ihc0ztyKJenY9nZDWf9y OYBMiDdv3v3h9H2YqmOWAum1xz+zWwFVDsF5/qQqenU30Y7B+7slN9/akQGbanfJ0eTY glSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yGxSjREd; 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 c25si10919803pgm.73.2019.08.27.01.17.32; Tue, 27 Aug 2019 01:17:47 -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=yGxSjREd; 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 S1726735AbfH0Hyo (ORCPT + 99 others); Tue, 27 Aug 2019 03:54:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:46382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729193AbfH0Hyl (ORCPT ); Tue, 27 Aug 2019 03:54:41 -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 2B5EE206BA; Tue, 27 Aug 2019 07:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892480; bh=QfCjO8LCovNwH1MRrDpyQEBYvOGF0awCtZXeqsF6glM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yGxSjREdcxNgZhxtfl4KB436OnLJqhm1igfDPkhjUqDOe9oNcVzwkxsmaQxA7m1cd sZ05Skpaf9QyO8xHhYKyGCmNaP5ZSBwM7ccAfh4uiK4+xkxI96Zkc5i9TzRHEfaZBg 0mSPGQAxDJg/9cfG+6nzN7KOAZAbKMSPbzhU3FdQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Tao , Mikulas Patocka , Mike Snitzer Subject: [PATCH 4.14 52/62] dm table: fix invalid memory accesses with too high sector number Date: Tue, 27 Aug 2019 09:50:57 +0200 Message-Id: <20190827072703.573713624@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072659.803647352@linuxfoundation.org> References: <20190827072659.803647352@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: Mikulas Patocka commit 1cfd5d3399e87167b7f9157ef99daa0e959f395d upstream. If the sector number is too high, dm_table_find_target() should return a pointer to a zeroed dm_target structure (the caller should test it with dm_target_is_valid). However, for some table sizes, the code in dm_table_find_target() that performs btree lookup will access out of bound memory structures. Fix this bug by testing the sector number at the beginning of dm_table_find_target(). Also, add an "inline" keyword to the function dm_table_get_size() because this is a hot path. Fixes: 512875bd9661 ("dm: table detect io beyond device") Cc: stable@vger.kernel.org Reported-by: Zhang Tao Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-table.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1308,7 +1308,7 @@ void dm_table_event(struct dm_table *t) } EXPORT_SYMBOL(dm_table_event); -sector_t dm_table_get_size(struct dm_table *t) +inline sector_t dm_table_get_size(struct dm_table *t) { return t->num_targets ? (t->highs[t->num_targets - 1] + 1) : 0; } @@ -1333,6 +1333,9 @@ struct dm_target *dm_table_find_target(s unsigned int l, n = 0, k = 0; sector_t *node; + if (unlikely(sector >= dm_table_get_size(t))) + return &t->targets[t->num_targets]; + for (l = 0; l < t->depth; l++) { n = get_child(n, k); node = get_node(t, l, n);