From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751373AbdK3WHz (ORCPT ); Thu, 30 Nov 2017 17:07:55 -0500 Received: from ale.deltatee.com ([207.54.116.67]:49942 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750768AbdK3WHy (ORCPT ); Thu, 30 Nov 2017 17:07:54 -0500 To: Serge Semin , jdmason@kudzu.us, dave.jiang@intel.com, Allen.Hubbe@emc.com, Shyam-sundar.S-k@amd.com, Xiangliang.Yu@amd.com Cc: Sergey.Semin@t-platforms.ru, linux-ntb@googlegroups.com, linux-kernel@vger.kernel.org References: <20171130213941.21114-1-fancer.lancer@gmail.com> From: Logan Gunthorpe Message-ID: <903ec475-1163-efd8-13ea-6b531210b928@deltatee.com> Date: Thu, 30 Nov 2017 15:07:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171130213941.21114-1-fancer.lancer@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 172.16.1.162 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-ntb@googlegroups.com, Sergey.Semin@t-platforms.ru, Xiangliang.Yu@amd.com, Shyam-sundar.S-k@amd.com, Allen.Hubbe@emc.com, dave.jiang@intel.com, jdmason@kudzu.us, fancer.lancer@gmail.com X-SA-Exim-Mail-From: logang@deltatee.com Subject: Re: [PATCH] NTB: Fix UB/bug in ntb_mw_get_align() X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/11/17 02:39 PM, Serge Semin wrote: > Simple (1 << pidx) operation causes undefined behaviour when > pidx >= 32. It must be casted to u64 to match the actual return > value of ntb_link_is_up() method, so to have all the possible > peer indexes covered and to get rid of undefined behaviour. > Additionally there are special macros in "linux/bitops.h" to perform > the bit-set-shift operations, so it's recommended to have them used > for proper bit setting. > > Signed-off-by: Serge Semin Reviewed-by: Logan Gunthorpe > --- > include/linux/ntb.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/ntb.h b/include/linux/ntb.h > index c1646f2c6344..488e586fb76c 100644 > --- a/include/linux/ntb.h > +++ b/include/linux/ntb.h > @@ -764,7 +764,7 @@ static inline int ntb_mw_get_align(struct ntb_dev *ntb, int pidx, int widx, > resource_size_t *size_align, > resource_size_t *size_max) > { > - if (!(ntb_link_is_up(ntb, NULL, NULL) & (1 << pidx))) > + if (!(ntb_link_is_up(ntb, NULL, NULL) & BIT_ULL(pidx))) > return -ENOTCONN; > > return ntb->ops->mw_get_align(ntb, pidx, widx, addr_align, size_align, >