From patchwork Tue Oct 27 13:54:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 307029 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=-12.8 required=3.0 tests=BAYES_00,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 3C959C55178 for ; Tue, 27 Oct 2020 17:46:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF2762231B for ; Tue, 27 Oct 2020 17:46:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603820810; bh=JQh2fpdPo7hQptUNAeVejo7y6ygRohzYnpAbQwiUe4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JD7Eg7VhFVGpGJneBn65Q0BAKR3miIP2iue71gg8yrfzlWNNA6dPlpop1/e4eP2z0 jyyAqjlIc1DyOYd798FW0hHvPHxNyf2rwhcLQPWtTBUKoty1Y2lFfFdhJKe1I+N3z0 7Rl33WADWmXhF1fMaAOR9qW2EMn8Y/OlRZLC1kQM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1822081AbgJ0Rqq (ORCPT ); Tue, 27 Oct 2020 13:46:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:52036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2901759AbgJ0O0T (ORCPT ); Tue, 27 Oct 2020 10:26:19 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 5FCD4207C3; Tue, 27 Oct 2020 14:26:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603808778; bh=JQh2fpdPo7hQptUNAeVejo7y6ygRohzYnpAbQwiUe4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H+bbcKHK3ncBVElllpZOvwFt/zcRr/43mOGXUvXvBLeMTd4v/nizQt9PtJ/9yhBFN r7OWiBJA7NzNcwTYI1P7diTQ9i1IEYiZXcn3ksxx6M8PqUyhuHyBE9+b1olRHf1igJ 4B9St8n4HucCWdUKRFoI1tq6BPUqVW2aBiX5+gcM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?utf-8?q?Pali_Roh=C3=A1r?= , Ulf Hansson , Sasha Levin Subject: [PATCH 4.19 221/264] mmc: sdio: Check for CISTPL_VERS_1 buffer size Date: Tue, 27 Oct 2020 14:54:39 +0100 Message-Id: <20201027135441.058597112@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135430.632029009@linuxfoundation.org> References: <20201027135430.632029009@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Pali Rohár [ Upstream commit 8ebe2607965d3e2dc02029e8c7dd35fbe508ffd0 ] Before parsing CISTPL_VERS_1 structure check that its size is at least two bytes to prevent buffer overflow. Signed-off-by: Pali Rohár Link: https://lore.kernel.org/r/20200727133837.19086-2-pali@kernel.org Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/mmc/core/sdio_cis.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c index f8c372839d244..2ca5cd79018b4 100644 --- a/drivers/mmc/core/sdio_cis.c +++ b/drivers/mmc/core/sdio_cis.c @@ -30,6 +30,9 @@ static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func, unsigned i, nr_strings; char **buffer, *string; + if (size < 2) + return 0; + /* Find all null-terminated (including zero length) strings in the TPLLV1_INFO field. Trailing garbage is ignored. */ buf += 2;