From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751241AbaDOLgy (ORCPT ); Tue, 15 Apr 2014 07:36:54 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:51074 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751094AbaDOLgw (ORCPT ); Tue, 15 Apr 2014 07:36:52 -0400 MIME-Version: 1.0 In-Reply-To: <20140415111800.GW4963@mwanda> References: <534c5757.VydWMxxcqkXGiwNa%akpm@linux-foundation.org> <20140415111800.GW4963@mwanda> Date: Tue, 15 Apr 2014 14:36:50 +0300 Message-ID: Subject: Re: + lib-stringc-strlcpy-might-read-too-far.patch added to -mm tree From: Alexey Dobriyan To: Dan Carpenter Cc: Linux Kernel , Vegard Nossum , Andrew Morton Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 15, 2014 at 2:18 PM, Dan Carpenter wrote: > On Tue, Apr 15, 2014 at 01:49:38PM +0300, Alexey Dobriyan wrote: >> Return value matters. It may not matter for kernel, because kernel is >> not heavy string user. >> But it is better to not diverge from master code: >> http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/strlcpy.c?rev=1.11 >> > > Oh... Hm. Maybe we should drop this patch then. > >> Counter-rationale: >> * strlcpy() accepts strings, so if you're giving raw buffer you're >> doing it wrong. >> * last byte of last page argument is bogus because kernel copies data >> from userspace first. > > The last byte of the page argument seems possible: > > foo = kmalloc(); > copy_from_user(foo, arg, sizeof(foo)); Correct code would do foo->bar[sizeof(foo->bar)-1] = '\0'; if this field is a string. > strlcpy(dest.str, foo->bar, sizeof(dest.str));