From patchwork Sat Oct 11 11:46:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tilman Schmidt X-Patchwork-Id: 398844 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id CB291140145 for ; Sat, 11 Oct 2014 22:47:53 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752398AbaJKLr3 (ORCPT ); Sat, 11 Oct 2014 07:47:29 -0400 Received: from gimli.pxnet.com ([89.1.7.7]:49806 "EHLO mail.pxnet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752116AbaJKLrD (ORCPT ); Sat, 11 Oct 2014 07:47:03 -0400 Received: from xenon.ts.pxnet.com (p57A57B2C.dip0.t-ipconnect.de [87.165.123.44]) (user=ts author=<> mech=DIGEST-MD5 bits=0) by mail.pxnet.com (8.13.8/8.13.8) with ESMTP id s9BBkh5O020821 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 11 Oct 2014 13:46:45 +0200 Received: by xenon.ts.pxnet.com (Postfix, from userid 1000) id 6866F140081; Sat, 11 Oct 2014 13:46:30 +0200 (CEST) Message-Id: In-Reply-To: References: From: Tilman Schmidt Subject: [PATCH 07/12] isdn/capi: prevent index overrun from command_2_index() To: netdev@vger.kernel.org Cc: David Miller , Dave Jones , Hansjoerg Lipp , Karsten Keil , isdn4linux@listserv.isdn4linux.de Date: Sat, 11 Oct 2014 13:46:30 +0200 (CEST) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (mail.pxnet.com [89.1.7.7]); Sat, 11 Oct 2014 13:46:45 +0200 (CEST) X-Scanned-By: MIMEDefang 2.70 on 89.1.7.7 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The result of the function command_2_index() is used to index two arrays mnames[] and cpars[] with max. index 0x4e but in its current form that function can produce results up to 3*(0x9+0x9)+0x7f = 0xb5. Fix by clamping all result values potentially overrunning the arrays to zero which is already handled as an invalid value. Re-spotted with Coverity. Signed-off-by: Tilman Schmidt --- drivers/isdn/capi/capiutil.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/isdn/capi/capiutil.c b/drivers/isdn/capi/capiutil.c index 4073d16..b501d76 100644 --- a/drivers/isdn/capi/capiutil.c +++ b/drivers/isdn/capi/capiutil.c @@ -207,6 +207,8 @@ static unsigned command_2_index(unsigned c, unsigned sc) c = 0x9 + (c & 0x0f); else if (c == 0x41) c = 0x9 + 0x1; + if (c > 0x18) + c = 0x00; return (sc & 3) * (0x9 + 0x9) + c; }