From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752822AbdFUQkm (ORCPT ); Wed, 21 Jun 2017 12:40:42 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33296 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751674AbdFUQkk (ORCPT ); Wed, 21 Jun 2017 12:40:40 -0400 Date: Wed, 21 Jun 2017 18:40:36 +0200 From: Ingo Molnar To: zhong jiang Cc: akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com, minchan@kernel.org, mhocko@suse.com, hpa@zytor.com, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative Message-ID: <20170621164036.4findvvz7jj4cvqo@gmail.com> References: <1498045437-7675-1-git-send-email-zhongjiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1498045437-7675-1-git-send-email-zhongjiang@huawei.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * zhong jiang wrote: > when shift expoment is negative, left shift alway zero. therefore, we > modify the logic to avoid the warining. > > Signed-off-by: zhong jiang > --- > arch/x86/include/asm/futex.h | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h > index b4c1f54..2425fca 100644 > --- a/arch/x86/include/asm/futex.h > +++ b/arch/x86/include/asm/futex.h > @@ -49,8 +49,12 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr) > int cmparg = (encoded_op << 20) >> 20; > int oldval = 0, ret, tem; > > - if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) > - oparg = 1 << oparg; > + if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) { > + if (oparg >= 0) > + oparg = 1 << oparg; > + else > + oparg = 0; > + } Could we avoid all these complications by using an unsigned type? Thanks, Ingo From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f198.google.com (mail-wr0-f198.google.com [209.85.128.198]) by kanga.kvack.org (Postfix) with ESMTP id B6F226B041E for ; Wed, 21 Jun 2017 12:40:40 -0400 (EDT) Received: by mail-wr0-f198.google.com with SMTP id l34so32275722wrc.12 for ; Wed, 21 Jun 2017 09:40:40 -0700 (PDT) Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com. [2a00:1450:400c:c0c::244]) by mx.google.com with ESMTPS id r195si17175253wmd.24.2017.06.21.09.40.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jun 2017 09:40:39 -0700 (PDT) Received: by mail-wr0-x244.google.com with SMTP id z45so27910286wrb.2 for ; Wed, 21 Jun 2017 09:40:39 -0700 (PDT) Date: Wed, 21 Jun 2017 18:40:36 +0200 From: Ingo Molnar Subject: Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative Message-ID: <20170621164036.4findvvz7jj4cvqo@gmail.com> References: <1498045437-7675-1-git-send-email-zhongjiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1498045437-7675-1-git-send-email-zhongjiang@huawei.com> Sender: owner-linux-mm@kvack.org List-ID: To: zhong jiang Cc: akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com, minchan@kernel.org, mhocko@suse.com, hpa@zytor.com, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org * zhong jiang wrote: > when shift expoment is negative, left shift alway zero. therefore, we > modify the logic to avoid the warining. > > Signed-off-by: zhong jiang > --- > arch/x86/include/asm/futex.h | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h > index b4c1f54..2425fca 100644 > --- a/arch/x86/include/asm/futex.h > +++ b/arch/x86/include/asm/futex.h > @@ -49,8 +49,12 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr) > int cmparg = (encoded_op << 20) >> 20; > int oldval = 0, ret, tem; > > - if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) > - oparg = 1 << oparg; > + if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) { > + if (oparg >= 0) > + oparg = 1 << oparg; > + else > + oparg = 0; > + } Could we avoid all these complications by using an unsigned type? Thanks, Ingo -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org