From patchwork Wed Jun 20 10:41:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10476885 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 8B97E604D3 for ; Wed, 20 Jun 2018 10:42:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C2C428E19 for ; Wed, 20 Jun 2018 10:42:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7095E28E1D; Wed, 20 Jun 2018 10:42:21 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 0F8CC28E19 for ; Wed, 20 Jun 2018 10:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754104AbeFTKmH (ORCPT ); Wed, 20 Jun 2018 06:42:07 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:34848 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753266AbeFTKmF (ORCPT ); Wed, 20 Jun 2018 06:42:05 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5KAccVE150963; Wed, 20 Jun 2018 10:42:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2017-10-26; bh=7i/vmRlobVrE2vdA5mnL9TySz8kvqw3XRhQYm/s//1o=; b=DU4Xjzs7tXz3/sbDZqLnrhVwFwGkmnUwpR/cdiDo9dgCcF4Bh/AjOuZnGWDYhwWMIR2i xg6H/BZWRwT92j8XYovCnN1GY3haBm8DGvKNwYfjTDZFskMWINgNWjpovHThacqEIGk9 WsIa02c2NBzwzyElHywxzE6NEClL6fYqybdaPTrs7zD9miN5XMWbSCk0IyJVn2JZEDkl BsqyVW4y2eXO9My9XP/t0a85ZxLL2UcRs+G8lR/PeR3r5VxhDpmgE4hqvcKtyQfVoHbq s4ujHfy+AUaBL2VQaKWKlRq0k4zArRuUP6NpTWx4P9+OkgE/gXJnQORr786q1VJ08G93 XQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2jmu6xuu5t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jun 2018 10:42:01 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5KAg0ZH014927 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jun 2018 10:42:01 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w5KAg05B022387; Wed, 20 Jun 2018 10:42:00 GMT Received: from kili.mountain (/197.157.34.185) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 20 Jun 2018 03:41:59 -0700 Date: Wed, 20 Jun 2018 13:41:51 +0300 From: Dan Carpenter To: Scott Bauer Cc: Jonathan Derrick , Jens Axboe , linux-block@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] block: sed-opal: Fix a couple off by one bugs Message-ID: <20180620104151.yhvcgbcbkkwj4cuk@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8929 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806200122 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP resp->num is the number of tokens in resp->tok[]. It gets set in response_parse(). So if n == resp->num then we're reading beyond the end of the data. Fixes: 455a7b238cd6 ("block: Add Sed-opal library") Signed-off-by: Dan Carpenter Reviewed-by: Scott Bauer Tested-by: Scott Bauer --- Static analysis. Not tested. This matches the checking in response_get_token(). My other concern is that there isn't checking in response_parse() to ensure that we don't go over MAX_TOKS (64) entries. If the firmware is buggy we're probably very screwed already, so it doesn't necessarily make a lot of difference at runtime but it might make static analysis easier if we knew the value of resp->num was in the 1-64 range. diff --git a/block/sed-opal.c b/block/sed-opal.c index 945f4b8610e0..e0de4dd448b3 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -877,7 +877,7 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, return 0; } - if (n > resp->num) { + if (n >= resp->num) { pr_debug("Response has %d tokens. Can't access %d\n", resp->num, n); return 0; @@ -916,7 +916,7 @@ static u64 response_get_u64(const struct parsed_resp *resp, int n) return 0; } - if (n > resp->num) { + if (n >= resp->num) { pr_debug("Response has %d tokens. Can't access %d\n", resp->num, n); return 0;