From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758877AbZEKT3t (ORCPT ); Mon, 11 May 2009 15:29:49 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758696AbZEKT3g (ORCPT ); Mon, 11 May 2009 15:29:36 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:57674 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758675AbZEKT3f (ORCPT ); Mon, 11 May 2009 15:29:35 -0400 Date: Mon, 11 May 2009 12:26:59 -0700 (PDT) From: Linus Torvalds X-X-Sender: torvalds@localhost.localdomain To: Al Viro cc: Jeff Mahoney , Andrew Morton , Linux Kernel Mailing List , Al Viro Subject: Re: [PATCH] dup2: Fix return value with oldfd == newfd and invalid fd In-Reply-To: <20090511191142.GK8633@ZenIV.linux.org.uk> Message-ID: References: <4A086D9E.60308@suse.com> <20090511191142.GK8633@ZenIV.linux.org.uk> User-Agent: Alpine 2.01 (LFD 1184 2008-12-16) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 11 May 2009, Al Viro wrote: > > I'm not sure that it's a right fix, actually. Note that userland declaration > of that sucker is int dup2(int, int); so should we really take unsigned int > as arguments? Hmm. They've been "unsigned int" for as long as our history goes back (including BK), but yes, making them "int" would have hidden this issue as well. That said, I think we had reasons to do our fd's as unsigned, ie the whole "compare against MAX" thing that doesn't take negative values into account. In fact, I think we should do more of those. Right now we literally depend on things like "max_fds" being "unsigned int", and that the compiler then turns all the if (fd < fdt->max_fds) tests silently into unsigned tests even when 'fd' is 'int'. So I suspect we should probably make fs/file.c use _more_ "unsigned int" rather than having less of them. Linus