From patchwork Tue Oct 27 13:50:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 311794 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=unavailable 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 72823C4363A for ; Tue, 27 Oct 2020 18:12:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2536521556 for ; Tue, 27 Oct 2020 18:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603822378; bh=JQh2fpdPo7hQptUNAeVejo7y6ygRohzYnpAbQwiUe4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wHCfFQ8SDT68CSFVNfuC/uwNDGtDEctHoZ0HFIP9q3yA6/GSHTmuhpwRLpQFhHPjv 7U28hIV9xxXf8wVbwZm/6iJFh62lgzBkzBoM+OZIAE7DJZUVHpR7M/F/QnynHpx3jP 1YMB5+3wHEIwue2UY2BgUjNll6OZZQTpQ+l/KrEQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756636AbgJ0OOl (ORCPT ); Tue, 27 Oct 2020 10:14:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:36316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756631AbgJ0OOl (ORCPT ); Tue, 27 Oct 2020 10:14:41 -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 950562072D; Tue, 27 Oct 2020 14:14:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603808081; bh=JQh2fpdPo7hQptUNAeVejo7y6ygRohzYnpAbQwiUe4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mzxT8WQl9/N4/uVegSw6D2Jt8VRAfoWwQdKgHvIuJDxXtgdwpEc+9/FA9l/jWuQtJ y3xeCIu2vTLKoVRB931WUtQrOZwobo3x+JY83fKOu6cp9oX9RHZwr5VlXbzd2hiLz+ 9XmHE5k2OqpDieBtggKNFE00V0s3C8z4KeMo+DFU= 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.14 150/191] mmc: sdio: Check for CISTPL_VERS_1 buffer size Date: Tue, 27 Oct 2020 14:50:05 +0100 Message-Id: <20201027134916.930575556@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@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;