From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Gleixner Subject: Re: [PATCH v2 1/1] futex: remove duplicated code and fix UB Date: Fri, 25 Aug 2017 22:43:41 +0200 (CEST) Message-ID: References: <20170824073105.3901-1-jslaby@suse.cz> <20170824094756.GA6346@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20170824094756.GA6346@arm.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org List-Archive: List-Post: To: Will Deacon Cc: linux-mips@linux-mips.org, Rich Felker , linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org, peterz@infradead.org, Benjamin Herrenschmidt , Max Filippov , Paul Mackerras , "H. Peter Anvin" , sparclinux@vger.kernel.org, Jiri Slaby , Jonas Bonn , linux-s390@vger.kernel.org, linux-arch@vger.kernel.org, Yoshinori Sato , linux-hexagon@vger.kernel.org, Helge Deller , x86@kernel.org, "James E.J. Bottomley" , mingo@redhat.com, Catalin Marinas , dvhart@infradead.org, Matt Turner , linux-snps-arc@lists.infradead.org, Fenghua Yu , Arnd Bergmann , linux-xtensa@linux-xtensa.org, Stefan Kristiansson List-ID: On Thu, 24 Aug 2017, Will Deacon wrote: > On Thu, Aug 24, 2017 at 09:31:05AM +0200, Jiri Slaby wrote: > > +static int futex_atomic_op_inuser(unsigned int encoded_op, u32 __user *uaddr) > > +{ > > + unsigned int op = (encoded_op & 0x70000000) >> 28; > > + unsigned int cmp = (encoded_op & 0x0f000000) >> 24; > > + int oparg = sign_extend32((encoded_op & 0x00fff000) >> 12, 12); > > + int cmparg = sign_extend32(encoded_op & 0x00000fff, 12); > > + int oldval, ret; > > + > > + if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) { > > + if (oparg < 0 || oparg > 31) > > + return -EINVAL; > > + oparg = 1 << oparg; > > + } > > + > > + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32))) > > + return -EFAULT; > > + > > + ret = arch_futex_atomic_op_inuser(op, oparg, &oldval, uaddr); > > + if (ret) > > + return ret; > > We could move the pagefault_{disable,enable} calls here, and then remove > them from the futex_atomic_op_inuser callsites elsewhere in futex.c Correct, but we can do that after getting this in. Thanks, tglx