From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_MUTT 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 38B24C28CC7 for ; Mon, 10 Jun 2019 14:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9CC42085A for ; Mon, 10 Jun 2019 14:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560175744; bh=Dmhjn6dmerxXt3ol9jRCHnE5w1zR4m9csfEWBzDuhn4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=l3+9AucNH866KYOroPvC2fMTPC/F0DnP8Kn7FU9cbXi9mgQYy2uYMmyGJTuVP/Fpc NP2QNog5powRR7zk60tshvNXE8nv6krnB0+I2QFjQr4uRAtBfhEASBTJ9caVMr8S1T Zkxsiuqh0O5KcHASoJg2QXE8wbML48Kq4yFTqtA8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390723AbfFJOJD (ORCPT ); Mon, 10 Jun 2019 10:09:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:39286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390707AbfFJOJD (ORCPT ); Mon, 10 Jun 2019 10:09:03 -0400 Received: from localhost (unknown [37.142.3.125]) (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 C7D22207E0; Mon, 10 Jun 2019 14:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560175742; bh=Dmhjn6dmerxXt3ol9jRCHnE5w1zR4m9csfEWBzDuhn4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=k3TGXv+nJgo3yOOp07fNs9ycIRFhMbZiT4PcS0cEAJ02ju98idOf2y9PHPKHXF6V+ w8ZxiPBtWL/+Zz6AQVV3DxIbWnfmd/6CJYLx8IuuIFRoVQGlu4QTyvf9sDzgPcVJou XmQ2mMHsCGStAcmRMU6mZ8bQEfW17nWTl9HF3Txs= Date: Mon, 10 Jun 2019 17:08:58 +0300 From: Leon Romanovsky To: Jason Gunthorpe Cc: Dan Carpenter , Yishai Hadas , Doug Ledford , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] IB/mlx4: prevent undefined shift in set_user_sq_size() Message-ID: <20190610140858.GA6369@mtr-leonro.mtl.com> References: <20190608092231.GA28890@mwanda> <20190610132849.GD18468@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190610132849.GD18468@ziepe.ca> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 10, 2019 at 10:28:49AM -0300, Jason Gunthorpe wrote: > On Sat, Jun 08, 2019 at 12:22:31PM +0300, Dan Carpenter wrote: > > The ucmd->log_sq_bb_count is a u8 that comes from the user. If it's > > larger than the number of bits in an int then that's undefined behavior. > > It turns out this doesn't really cause an issue at runtime but it's > > still nice to clean it up. > > > > Signed-off-by: Dan Carpenter > > --- > > drivers/infiniband/hw/mlx4/qp.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c > > index 5221c0794d1d..9f6eb23e8044 100644 > > --- a/drivers/infiniband/hw/mlx4/qp.c > > +++ b/drivers/infiniband/hw/mlx4/qp.c > > @@ -439,7 +439,8 @@ static int set_user_sq_size(struct mlx4_ib_dev *dev, > > struct mlx4_ib_create_qp *ucmd) > > { > > /* Sanity check SQ size before proceeding */ > > - if ((1 << ucmd->log_sq_bb_count) > dev->dev->caps.max_wqes || > > + if (ucmd->log_sq_bb_count > 31 || > > + (1 << ucmd->log_sq_bb_count) > dev->dev->caps.max_wqes || > > Surely this should use check_shl_overflow() ? Yes > > Jason