From patchwork Tue Sep 1 15:10:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 264445 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=-13.0 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 E87FDC433E7 for ; Tue, 1 Sep 2020 17:15:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA9F12078B for ; Tue, 1 Sep 2020 17:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598980510; bh=8kd2JWfylGbyX5junfsVFBIFiC5m0s7OyUEiuP3YRFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=V0qWW6QUyUE2VzBHpFAinDWLpzU64zHX67hJOzA74XajiYCn5+ZgnUIWinvX0eFV+ jg8QEiZ9paqiUIwE3n8qAay9kiccSVhU4CwEB4LXz30U4N60FoTg45ZAPOiqKbeCng 7FQKCkWDbd5PmVwfpMD+8h0H6c9QSlP0vRZ6DF+0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728089AbgIARPG (ORCPT ); Tue, 1 Sep 2020 13:15:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:59184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729172AbgIAPPE (ORCPT ); Tue, 1 Sep 2020 11:15:04 -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 12993206FA; Tue, 1 Sep 2020 15:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598973303; bh=8kd2JWfylGbyX5junfsVFBIFiC5m0s7OyUEiuP3YRFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bKkk0w124Z8OXZZvyiXBC+ciL7jZq8xULnDwiolbPsmWl934ohoq2Vcvpihh/BngE cn6z/Q6NsqUE1fgmmuH1AkHPiUgTERPUaM7PpppBmmIFIwdvoXYJtzM9xX+FfHqTFf y1bNw/h5e7hD/DSXrXe31deqcLlIS31pGNybNYH4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 25/78] cec-api: prevent leaking memory through hole in structure Date: Tue, 1 Sep 2020 17:10:01 +0200 Message-Id: <20200901150925.999428474@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150924.680106554@linuxfoundation.org> References: <20200901150924.680106554@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Hans Verkuil [ Upstream commit 6c42227c3467549ddc65efe99c869021d2f4a570 ] Fix this smatch warning: drivers/media/cec/core/cec-api.c:156 cec_adap_g_log_addrs() warn: check that 'log_addrs' doesn't leak information (struct has a hole after 'features') Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/staging/media/cec/cec-api.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/staging/media/cec/cec-api.c b/drivers/staging/media/cec/cec-api.c index e274e2f223986..264bb7d1efcb8 100644 --- a/drivers/staging/media/cec/cec-api.c +++ b/drivers/staging/media/cec/cec-api.c @@ -141,7 +141,13 @@ static long cec_adap_g_log_addrs(struct cec_adapter *adap, struct cec_log_addrs log_addrs; mutex_lock(&adap->lock); - log_addrs = adap->log_addrs; + /* + * We use memcpy here instead of assignment since there is a + * hole at the end of struct cec_log_addrs that an assignment + * might ignore. So when we do copy_to_user() we could leak + * one byte of memory. + */ + memcpy(&log_addrs, &adap->log_addrs, sizeof(log_addrs)); if (!adap->is_configured) memset(log_addrs.log_addr, CEC_LOG_ADDR_INVALID, sizeof(log_addrs.log_addr));