From patchwork Tue Oct 27 13:49:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 290191 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 B99FBC55178 for ; Tue, 27 Oct 2020 14:00:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7619521D7B for ; Tue, 27 Oct 2020 14:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807241; bh=CO+FUODqhobCGWD5uWt+v0rTAV+RLiKHYwAG7UiGCoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dNj2eSmzmYwKq28TQup4WzQLxm/QbDkeRQ1uEJkChgigm8gt7iwkUacLvXgdpn2yS yMCk5lfdIKT7u+g6TxDXkJoroXLMUsbRwFUA75uViH5SoEw/nTFRjI24UXZySZCRZ3 9pOqhi6FRT//VsBugVpNhkIvHJICFLOH7mYGH324= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504307AbgJ0OAj (ORCPT ); Tue, 27 Oct 2020 10:00:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:47716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753574AbgJ0OAR (ORCPT ); Tue, 27 Oct 2020 10:00:17 -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 BCF7C2068D; Tue, 27 Oct 2020 14:00:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807217; bh=CO+FUODqhobCGWD5uWt+v0rTAV+RLiKHYwAG7UiGCoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n15kv+WcvZQGIqg4KfYHVGC6u5cgO3NfmfITvCQJS6w10UHvmJXrQB2j0/zb7dKKK tne9f8IaBnlJQK6P1G75/7QDs3i0xhiM2dD0nxgtt+tvNdeOMLgj1wkrEwHiPPuJIb pisFZNKbVu6IgQwr+ZhiZeQNHWrSv7s/EceHu94M= 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.4 085/112] mmc: sdio: Check for CISTPL_VERS_1 buffer size Date: Tue, 27 Oct 2020 14:49:55 +0100 Message-Id: <20201027134904.567636192@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@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 8e94e555b788d..8651bd30863d4 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;