Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751426AbaDAMfv (ORCPT ); Tue, 1 Apr 2014 08:35:51 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:18923 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750996AbaDAMft (ORCPT ); Tue, 1 Apr 2014 08:35:49 -0400 Date: Tue, 1 Apr 2014 15:35:34 +0300 From: Dan Carpenter To: Vegard Nossum , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , stable@vger.kernel.org Subject: Re: [PATCH] isdnloop: NUL-terminate strings from userspace Message-ID: <20140401123534.GE18506@mwanda> References: <1396346898-8950-1-git-send-email-vegard.nossum@oracle.com> <20140401103020.GG24150@order.stressinduktion.org> <533A990D.2040609@oracle.com> <20140401110255.GH24150@order.stressinduktion.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140401110255.GH24150@order.stressinduktion.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 01, 2014 at 01:02:55PM +0200, Hannes Frederic Sowa wrote: > On Tue, Apr 01, 2014 at 12:46:37PM +0200, Vegard Nossum wrote: > > On 04/01/2014 12:30 PM, Hannes Frederic Sowa wrote: > > >Looking down the problem, it seems the problem is that the strlen in > > >strlcpy > > >could read beyond the input buffer? > > > > > >To prevent this problem in other parts of the kernel wouldn't it be better > > >to > > >replace the strlen with strnlen in strlcpy? > > > > Sorry, I should have included the link to the previous thread: > > https://lkml.org/lkml/2014/3/7/712 > > > > I only resent (adding netdev to Cc) to get this into David Miller's > > patch queue. > > Ah ok, sorry I don't follow lkml as closely as netdev@. > > > As you can see from the previous discussion, we _could_ change the Linux > > kernel's definition of strlcpy(), but I wouldn't recommend it for the > > following reasons: > > > > 1. Both BSD man page and BSD implementation _require_ the source string > > to be 0-terminated. Changing the semantics of strlcpy() in the Linux > > kernel would probably be a bad idea and cause even more confusion that > > what we already have. > > Sure, we shouldn't change the documented semantics. If at all it would > be an additional safety net. Your patch would still be needed. > Guys, really? How would the patch "still be needed"? I feel like if someone said we had to rub a chicken head on this code we do it in the name of security... I don't understand what you think the point of strlcpy() is, if it's not to deal with source strings which aren't NUL terminated. I still maintain that the since the stack is full of NUL characters the current implimentation of strlcpy() is ok for this isdn_loop function and the patch is not needed at all without the strnlen() change. However for other heap allocated variables then I could imagine that the strlen() might be a problem. I have two theories why we have never seen problems with this in running code. 1) The string would have to be at the end of a struct allocated at the end of a page. You have to be very unlucky to hit this requirement. 2) Most people pass valid data. regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/