From patchwork Tue Sep 1 15:08:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 310476 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 725BCC433E2 for ; Tue, 1 Sep 2020 15:37:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38AED20E65 for ; Tue, 1 Sep 2020 15:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974669; bh=Oq7KjuIEGAsnarIYTg82Iav+HRMBExE8AuCjNT05MZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=YCvhG/AM3uIxv0vihAFWQwG5QkjVHajsjKeSG8/3kYFnKbgZyvtOBEGsd1r5cTji1 FlM5baxySXD8+Rc9fj5gMgMKo75+aEJk/3Q5hno3lMtQiQaOKpq7O+RUYbBazzMuCb 5xUymkBg8ZGiuh+TFNBlS9bZ5DAt1nsqDt89SQIc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731359AbgIAPhq (ORCPT ); Tue, 1 Sep 2020 11:37:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:46126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731355AbgIAPho (ORCPT ); Tue, 1 Sep 2020 11:37:44 -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 A2A5921582; Tue, 1 Sep 2020 15:37:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974664; bh=Oq7KjuIEGAsnarIYTg82Iav+HRMBExE8AuCjNT05MZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XcE6pdUFXkM+3zTsw+wZqFsxF2D+LcsBorvrK/4yxkG/dxQIHTcGuPDNg8nkpenqK XqRHo8PK/HT9/ppI2aQ7ba5ZxR2B+TqCLCNomuJK6ykBvtWMugGdfNhCqsTKDUmh5p N6J34xROuc/BKnTRTL1UEUvSkCARTGEhhYbkVuAI= 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 5.8 046/255] cec-api: prevent leaking memory through hole in structure Date: Tue, 1 Sep 2020 17:08:22 +0200 Message-Id: <20200901151002.951614154@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901151000.800754757@linuxfoundation.org> References: <20200901151000.800754757@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/media/cec/core/cec-api.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/cec/core/cec-api.c b/drivers/media/cec/core/cec-api.c index 17d1cb2e5f976..f922a2196b2b7 100644 --- a/drivers/media/cec/core/cec-api.c +++ b/drivers/media/cec/core/cec-api.c @@ -147,7 +147,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));