From patchwork Wed Apr 11 19:06:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Shaia X-Patchwork-Id: 10336781 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 D3ACB60134 for ; Wed, 11 Apr 2018 19:10:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C512A27F91 for ; Wed, 11 Apr 2018 19:10:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B876827F98; Wed, 11 Apr 2018 19:10:13 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 45C4127F91 for ; Wed, 11 Apr 2018 19:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935244AbeDKTGh (ORCPT ); Wed, 11 Apr 2018 15:06:37 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:59002 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935241AbeDKTGg (ORCPT ); Wed, 11 Apr 2018 15:06:36 -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 w3BJ69mQ149641; Wed, 11 Apr 2018 19:06:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2017-10-26; bh=2b5YQRVJLBa0Ni2ULXxNJLZCsg9sSn1qwcAqS9oW9EA=; b=wNtC1d48I4lwD6m9R6YfRHTqK3aP4kj864QYeK825WGE/eXP6hG8JqQPSoWVcirgNvNc 0X+tEC+zNDaL6ZoX9QGb5JmrOd6VkjUTGlTH4Bv0SRl5bLvLR9V55okreh11H90ewOkb hBBp8cBuzopBMGe0sDNKiCwDgaQxsmYWr7gTXQbWfy+q/3w3W6hNGMRlLTDZSUMSLmH/ bfmE1FZTTV4Pw1SfRt6hO2R3e10Qk9ZF8uZ5YmPxtt8o9Bw1l1TCLPuxySbA5UPx8jPS zR1yECXci2LsC9K5GJwvUedsjSyMekALTrSjaIEg4udUY48JimLgBYTSY7//Vr0zm3Pw xQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2h6pn4rm40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Apr 2018 19:06:29 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w3BJ6TtN001922 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Apr 2018 19:06:29 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w3BJ6SLI012499; Wed, 11 Apr 2018 19:06:29 GMT Received: from localhost.localdomain (/77.138.186.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 11 Apr 2018 12:06:28 -0700 From: Yuval Shaia To: dledford@redhat.com, jgg@mellanox.com, leonro@mellanox.com, linux-rdma@vger.kernel.org, michael.j.ruhl@intel.com Cc: Yuval Shaia Subject: [PATCH v2] libibverb/examples: Protect against memory corruption Date: Wed, 11 Apr 2018 22:06:15 +0300 Message-Id: <20180411190615.5149-1-yuval.shaia@oracle.com> X-Mailer: git-send-email 2.14.3 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8860 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=821 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804110176 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make sure num_qp is less than MAX_QP so we will not overrun my_dest array. Signed-off-by: Yuval Shaia Reviewed-by: Zhu Yanjun --- v1 -> v2: * Accept comment from Ruhl, Michael J --- libibverbs/examples/srq_pingpong.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libibverbs/examples/srq_pingpong.c b/libibverbs/examples/srq_pingpong.c index c289b463..014d114f 100644 --- a/libibverbs/examples/srq_pingpong.c +++ b/libibverbs/examples/srq_pingpong.c @@ -759,6 +759,12 @@ int main(int argc, char *argv[]) return 1; } + if (num_qp >= MAX_QP) { + fprintf(stderr, "num_qp %d must be less than %d\n", num_qp, + MAX_QP - 1); + return 1; + } + num_wc = num_qp + rx_depth; wc = alloca(num_wc * sizeof *wc);