From patchwork Thu Jun 30 10:19:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 9207177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B125B6075A for ; Thu, 30 Jun 2016 10:36:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2B93284B8 for ; Thu, 30 Jun 2016 10:36:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 978BD284BF; Thu, 30 Jun 2016 10:36:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D065284B8 for ; Thu, 30 Jun 2016 10:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752060AbcF3Kg3 (ORCPT ); Thu, 30 Jun 2016 06:36:29 -0400 Received: from aer-iport-4.cisco.com ([173.38.203.54]:8438 "EHLO aer-iport-4.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751916AbcF3Kg2 (ORCPT ); Thu, 30 Jun 2016 06:36:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1724; q=dns/txt; s=iport; t=1467282988; x=1468492588; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=0Uk8yQdNyWTrzyMg0PTSW9ULCGTEATgCdEHk/Qq8FSk=; b=JM+s+Fqz7G1W9nQFkB5Q9GlQYuNa1Vbqfh92916vV4Q06Jl+4o1kmFiI bU8NtFp981f47spOXZNH4J0x8RcFxbKXFLxVDfgvCrKexhKI0JnXW1SA/ OoJyyKVoCJVdi79+zGVNpjJQlBalcmE8ypLGzWYTl3K2ngGLvhYEAhn8O s=; X-IronPort-AV: E=Sophos;i="5.26,551,1459814400"; d="scan'208";a="638292387" Received: from aer-iport-nat.cisco.com (HELO aer-core-1.cisco.com) ([173.38.203.22]) by aer-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jun 2016 10:19:35 +0000 Received: from cobaltpc1.rd.cisco.com ([10.47.79.81]) (authenticated bits=0) by aer-core-1.cisco.com (8.14.5/8.14.5) with ESMTP id u5UAJXNu008005 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NO); Thu, 30 Jun 2016 10:19:34 GMT From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Hans Verkuil Subject: [PATCH 2/2] cec-adap: prevent write to out-of-bounds array index Date: Thu, 30 Jun 2016 12:19:33 +0200 Message-Id: <1467281973-6889-3-git-send-email-hans.verkuil@cisco.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1467281973-6889-1-git-send-email-hans.verkuil@cisco.com> References: <1467281973-6889-1-git-send-email-hans.verkuil@cisco.com> X-Authenticated-User: hansverk Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP CEC_MSG_REPORT_PHYSICAL_ADDR can theoretically be received from an unregistered device, but in that case the code should not attempt to write the received physical address to the phys_addrs array. That would be pointless since there can be multiple unregistered devices that report a physical address. We just ignore those. While at it, improve the dprintk since it would attempt to read from that array as well with the same out-of-bounds problem. Signed-off-by: Hans Verkuil Reported-by: Dan Carpenter --- drivers/staging/media/cec/cec-adap.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/cec/cec-adap.c b/drivers/staging/media/cec/cec-adap.c index 98bdcf9..307af43 100644 --- a/drivers/staging/media/cec/cec-adap.c +++ b/drivers/staging/media/cec/cec-adap.c @@ -1442,12 +1442,15 @@ static int cec_receive_notify(struct cec_adapter *adap, struct cec_msg *msg, switch (msg->msg[1]) { /* The following messages are processed but still passed through */ - case CEC_MSG_REPORT_PHYSICAL_ADDR: - adap->phys_addrs[init_laddr] = - (msg->msg[2] << 8) | msg->msg[3]; - dprintk(1, "Reported physical address %04x for logical address %d\n", - adap->phys_addrs[init_laddr], init_laddr); + case CEC_MSG_REPORT_PHYSICAL_ADDR: { + u16 pa = (msg->msg[2] << 8) | msg->msg[3]; + + if (!from_unregistered) + adap->phys_addrs[init_laddr] = pa; + dprintk(1, "Reported physical address %x.%x.%x.%x for logical address %d\n", + cec_phys_addr_exp(pa), init_laddr); break; + } case CEC_MSG_USER_CONTROL_PRESSED: if (!(adap->capabilities & CEC_CAP_RC))