Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752963AbdC2Q4v (ORCPT ); Wed, 29 Mar 2017 12:56:51 -0400 Received: from mail-vk0-f41.google.com ([209.85.213.41]:34752 "EHLO mail-vk0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751216AbdC2Q4t (ORCPT ); Wed, 29 Mar 2017 12:56:49 -0400 MIME-Version: 1.0 In-Reply-To: References: <20170328145413.GA3164@redhat.com> <20170329163335.GA23977@redhat.com> From: Andy Lutomirski Date: Wed, 29 Mar 2017 09:56:27 -0700 Message-ID: Subject: Re: syscall_get_error() && TS_ checks To: Linus Torvalds Cc: Oleg Nesterov , Andrew Morton , Andy Lutomirski , Denys Vlasenko , "H. Peter Anvin" , Ingo Molnar , Jan Kratochvil , Pedro Alves , Thomas Gleixner , "the arch/x86 maintainers" , Linux Kernel Mailing List Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1711 Lines: 43 On Wed, Mar 29, 2017 at 9:45 AM, Linus Torvalds wrote: > On Wed, Mar 29, 2017 at 9:33 AM, Oleg Nesterov wrote: >> >> Firstly, why do we need the IS_ERR_VALUE() check? This is only used by >> do_signal/handle_signal, we do not care if it returns non-zero as long >> as the value can't be confused with -ERESTART.* codes. > > There are system calls that can return "negative" values that aren't errors. > > Notably mmap() can return a valid pointer with the high bit set. > > So syscall_get_error() should return 0 for not just positive return > values, but for those kinds of negative non-error values. > >> And why do we need the TS_ checks? > > Those may be bogus. > >> So why we can't simply change putreg32() to always sign-extend regs->ax >> regs->orig_ax and just do >> >> static inline long syscall_get_error(struct task_struct *task, >> struct pt_regs *regs) >> { >> return regs-ax; >> } > > That would be *complete* garbage. Lots of system calls return positive > values that sure as hell aren't errors. Does this cause an observable problem? The only things that care are: a) 32-bit debugger pokes some value with the high bit and a 64-bit debugger reads it back. I seriously doubt we care. b) 32-bit debugger pokes some value with the high bit set and the user code switches to 64-bit mode and reads RAX. This case is so terminally broken anyway that we definitely don't care. c) 32-bit debugger pokes some value with the high bit set and syscall_get_error happens. Oleg's proposed change won't change what we do, but it will dramatically simplify the code.