Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1316267ybg; Wed, 29 Jul 2020 10:56:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAv510CMEOcvY+Gste7FViCZMeP8BqKHpwJAhVm5U3CFYA6R0TvOdtTdPg/H6ERN01Ez2z X-Received: by 2002:a05:6402:1764:: with SMTP id da4mr13863231edb.187.1596045370669; Wed, 29 Jul 2020 10:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596045370; cv=none; d=google.com; s=arc-20160816; b=BIDyvvmIeym0oX5YRtYS1vkqIWMCSJGtplCvBi584whi5EPNnbKbdW6870cXpIDx/A /kkjKwlfM0UqQucvcenyHb81SZE7lIurLeeCN5jCM4IWh6XMXQsgc5yQDB/zB8hQxF00 K7ihdHNxieKQf4h7LrnsqZl2TgwVQTef7ZpcRxyCGdtUX7LUT04i2SMODy8YOrGUEm1O BapMSi31ixpnQQY1l6AtJLj6PPOulKLzlvqMgoZyxGjne1kE64pI1yUI6EyCeXudKzC9 sJI2UHrNKq1mp5AA9apfHtydZXM/XArP7l3C6b12qa1Qval9x440HPUHRrHTr+8VFLf/ dsPQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:from:references:cc:to:dkim-signature; bh=g/ocoqM5pkGRwSR1GarrpOt3G28eyY8xAguAVH+6ebk=; b=o1MxSFpLwzIP5KiVQhaB81kFPrJEXTaVPaFtEwtZYC5fwKjkAmsoFDIEC+ZcJp7XXD SyU7cuXtTvqb9PGk7TR2136X5DbBJ3HhA4N2UvaID56t+m2IGlv0XtxQc0DTU6JyoCq5 vKzDl8sPPiBSeyRuTFcc8n6Jgh77ao+yJAS8F9YNeaTKhMGyFqe4fximt20X9Nh0IFEE PJg0tNks4Zcqx3GpKENqE9qRPfGJd0KcRUh3AR27F68u4ez1cYphH0dx3LPUjFYbPg4A dWxIsy5DnrEw4p1cOnS3geEw3Yes0XzMvsx89QYmlNP59Xgc9kuvzH9MfG7x8PLVO1JN QqvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=PNhYMuFT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si527249edr.171.2020.07.29.10.55.48; Wed, 29 Jul 2020 10:56:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=PNhYMuFT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726533AbgG2RzM (ORCPT + 99 others); Wed, 29 Jul 2020 13:55:12 -0400 Received: from gateway24.websitewelcome.com ([192.185.50.93]:20893 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbgG2RzM (ORCPT ); Wed, 29 Jul 2020 13:55:12 -0400 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 3B63D611C for ; Wed, 29 Jul 2020 12:55:06 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 0qIEkF9VtSxZV0qIEkl5GM; Wed, 29 Jul 2020 12:55:06 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:Subject:From:References:Cc:To:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=g/ocoqM5pkGRwSR1GarrpOt3G28eyY8xAguAVH+6ebk=; b=PNhYMuFT0FrlsY1N4Z8cuMN1Pn kuN+r4K+cllJ1KeHH3Tpay2pojd+aKe+GKzz9Xq/LcI2ieagX7STrYhFG4Nrz11WPlwLh5F6r82A1 0Zhu2o1hw7ya3S3NWaszcM2iY5Cnm6ut/1lwKy8Qd7u1H6ttUfH/8SwP9HKpo5huS5V9Fei9IHQyy +x4SiJsHdc8tDiMh735Bz3viIBSJN+FAty0hfGrIXFvoIWCRCZ7Uh3FgFufJDCrIwuIZSM1kcxotr i3qNcN8ay+gw6EYnY3foaGFcV5472zxjxmjdVGdAVDu7WREyCryXkXPEL04WToA3BOgB9EFja/fnl 32zi8+vg==; Received: from 187-162-31-110.static.axtel.net ([187.162.31.110]:44700 helo=[192.168.15.2]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1k0qID-003vpn-Sf; Wed, 29 Jul 2020 12:55:05 -0500 To: Tomas Winkler , Greg Kroah-Hartman Cc: Alexander Usyskin , linux-kernel@vger.kernel.org, Ramalingam C , "Gustavo A . R . Silva" References: <20200729173204.3251582-1-tomas.winkler@intel.com> From: "Gustavo A. R. Silva" Autocrypt: addr=gustavo@embeddedor.com; keydata= xsFNBFssHAwBEADIy3ZoPq3z5UpsUknd2v+IQud4TMJnJLTeXgTf4biSDSrXn73JQgsISBwG 2Pm4wnOyEgYUyJd5tRWcIbsURAgei918mck3tugT7AQiTUN3/5aAzqe/4ApDUC+uWNkpNnSV tjOx1hBpla0ifywy4bvFobwSh5/I3qohxDx+c1obd8Bp/B/iaOtnq0inli/8rlvKO9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2CAY+QSUMebQRFjKavw XB/xE7fTt2ahuhHT8qQ/lWuRQedg4baInw9nhoPE+VenOzhGeGlsJ0Ys52sdXvUjUocKgUQq 6ekOHbcw919nO5L9J2ejMf/VC/quN3r3xijgRtmuuwZjmmi8ct24TpGeoBK4WrZGh/1hAYw4 ieARvKvgjXRstcEqM5thUNkOOIheud/VpY+48QcccPKbngy//zNJWKbRbeVnimua0OpqRXhC rEVm/xomeOvl1WK1BVO7z8DjSdEBGzbV76sPDJb/fw+y+VWrkEiddD/9CSfgfBNOb1p1jVnT 2mFgGneIWbU0zdDGhleI9UoQTr0e0b/7TU+Jo6TqwosP9nbk5hXw6uR5k5PF8ieyHVq3qatJ 9K1jPkBr8YWtI5uNwJJjTKIA1jHlj8McROroxMdI6qZ/wZ1ImuylpJuJwCDCORYf5kW61fcr HEDlIvGc371OOvw6ejF8ksX5+L2zwh43l/pKkSVGFpxtMV6d6J3eqwTafL86YJWH93PN+ZUh 6i6Rd2U/i8jH5WvzR57UeWxE4P8bQc0hNGrUsHQH6bpHV2lbuhDdqo+cM9ehGZEO3+gCDFmK rjspZjkJbB5Gadzvts5fcWGOXEvuT8uQSvl+vEL0g6vczsyPBtqoBLa9SNrSVtSixD1uOgyt AP7RWS474w== Subject: Re: [char-misc-next] mei: hdcp: fix mei_hdcp_verify_mprime() input paramter Message-ID: <66c9950c-ef54-423e-467f-38a9f7afb384@embeddedor.com> Date: Wed, 29 Jul 2020 13:01:05 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200729173204.3251582-1-tomas.winkler@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.162.31.110 X-Source-L: No X-Exim-ID: 1k0qID-003vpn-Sf X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187-162-31-110.static.axtel.net ([192.168.15.2]) [187.162.31.110]:44700 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/29/20 12:32, Tomas Winkler wrote: > wired_cmd_repeater_auth_stream_req_in has a variable > length array at the end. we use struct_size() overflow > macro to determine the size for the allocation and sending > size. > > Fixes: c56967d674e3 (mei: hdcp: Replace one-element array with flexible-array member) This also fixes: commit 0a1af1b5c18d ("misc/mei/hdcp: Verify M_prime") which introduced a potential stack overflow back in Feb 2019, hence it should be fixed in -stable, too. So, either both commit c56967d674e3 (mei: hdcp: Replace one-element array with flexible-array member) and this patch should be ported to -stable in order to fix a potential stack overflow due to commit 0a1af1b5c18d ("misc/mei/hdcp: Verify M_prime"), or a separate fix that doesn't touch the one-element array streams[1] in struct wired_cmd_repeater_auth_stream_req_in, but addresses the stack overflow should be crafted and applied to -stable. I can write that fix up for -stable if you want to go in that direction. Just let me know. > Cc: Ramalingam C > Cc: Gustavo A. R. Silva > Signed-off-by: Tomas Winkler > --- > drivers/misc/mei/hdcp/mei_hdcp.c | 38 ++++++++++++++++++-------------- > 1 file changed, 22 insertions(+), 16 deletions(-) > > diff --git a/drivers/misc/mei/hdcp/mei_hdcp.c b/drivers/misc/mei/hdcp/mei_hdcp.c > index d1d3e025ca0e..0e8f12e38494 100644 > --- a/drivers/misc/mei/hdcp/mei_hdcp.c > +++ b/drivers/misc/mei/hdcp/mei_hdcp.c > @@ -546,38 +546,44 @@ static int mei_hdcp_verify_mprime(struct device *dev, > struct hdcp_port_data *data, > struct hdcp2_rep_stream_ready *stream_ready) > { > - struct wired_cmd_repeater_auth_stream_req_in > - verify_mprime_in = { { 0 } }; > + struct wired_cmd_repeater_auth_stream_req_in *verify_mprime_in; > struct wired_cmd_repeater_auth_stream_req_out > verify_mprime_out = { { 0 } }; > struct mei_cl_device *cldev; > ssize_t byte; > + size_t cmd_size; > > if (!dev || !stream_ready || !data) > return -EINVAL; > > cldev = to_mei_cl_device(dev); > > - verify_mprime_in.header.api_version = HDCP_API_VERSION; > - verify_mprime_in.header.command_id = WIRED_REPEATER_AUTH_STREAM_REQ; > - verify_mprime_in.header.status = ME_HDCP_STATUS_SUCCESS; > - verify_mprime_in.header.buffer_len = > + cmd_size = struct_size(verify_mprime_in, streams, data->k); > + if (cmd_size == SIZE_MAX) > + return -EINVAL; > + > + verify_mprime_in = kzalloc(cmd_size, GFP_KERNEL); > + > + verify_mprime_in->header.api_version = HDCP_API_VERSION; > + verify_mprime_in->header.command_id = WIRED_REPEATER_AUTH_STREAM_REQ; > + verify_mprime_in->header.status = ME_HDCP_STATUS_SUCCESS; > + verify_mprime_in->header.buffer_len = > WIRED_CMD_BUF_LEN_REPEATER_AUTH_STREAM_REQ_MIN_IN; > > - verify_mprime_in.port.integrated_port_type = data->port_type; > - verify_mprime_in.port.physical_port = (u8)data->fw_ddi; > - verify_mprime_in.port.attached_transcoder = (u8)data->fw_tc; > + verify_mprime_in->port.integrated_port_type = data->port_type; > + verify_mprime_in->port.physical_port = (u8)data->fw_ddi; > + verify_mprime_in->port.attached_transcoder = (u8)data->fw_tc; > + > + memcpy(verify_mprime_in->m_prime, stream_ready->m_prime, HDCP_2_2_MPRIME_LEN); > + drm_hdcp_cpu_to_be24(verify_mprime_in->seq_num_m, data->seq_num_m); > > - memcpy(verify_mprime_in.m_prime, stream_ready->m_prime, > - HDCP_2_2_MPRIME_LEN); > - drm_hdcp_cpu_to_be24(verify_mprime_in.seq_num_m, data->seq_num_m); > - memcpy(verify_mprime_in.streams, data->streams, > + memcpy(verify_mprime_in->streams, data->streams, > array_size(data->k, sizeof(*data->streams))); Please, use flex_array_size() instead of array_size() here, like this: memcpy(verify_mprime_in->streams, data->streams, flex_array_size(verify_mprime_in, streams, data->k)); Thanks -- Gustavo > > - verify_mprime_in.k = cpu_to_be16(data->k); > + verify_mprime_in->k = cpu_to_be16(data->k); > > - byte = mei_cldev_send(cldev, (u8 *)&verify_mprime_in, > - sizeof(verify_mprime_in)); > + byte = mei_cldev_send(cldev, (u8 *)&verify_mprime_in, cmd_size); > + kfree(verify_mprime_in); > if (byte < 0) { > dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte); > return byte; >