Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751224AbbESUQq (ORCPT ); Tue, 19 May 2015 16:16:46 -0400 Received: from mail-la0-f54.google.com ([209.85.215.54]:36744 "EHLO mail-la0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750750AbbESUQp (ORCPT ); Tue, 19 May 2015 16:16:45 -0400 MIME-Version: 1.0 In-Reply-To: <20150519192206.GN4641@pd.tnic> References: <1432050210-32036-1-git-send-email-prarit@redhat.com> <20150519181334.GM4641@pd.tnic> <20150519192206.GN4641@pd.tnic> From: Andy Lutomirski Date: Tue, 19 May 2015 13:16:23 -0700 Message-ID: Subject: Re: [PATCH] x86, cpuinfo x86_model_id whitespace cleanup To: Borislav Petkov Cc: "linux-kernel@vger.kernel.org" , Fenghua Yu , Dave Hansen , Thomas Gleixner , Denys Vlasenko , Ingo Molnar , Brian Gerst , "H. Peter Anvin" , Igor Mammedov , "the arch/x86 maintainers" , Prarit Bhargava 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: 1481 Lines: 36 On Tue, May 19, 2015 at 12:22 PM, Borislav Petkov wrote: > On Tue, May 19, 2015 at 11:44:41AM -0700, Andy Lutomirski wrote: >> On May 19, 2015 11:13 AM, "Borislav Petkov" wrote: >> > >> > On Tue, May 19, 2015 at 01:25:59PM -0400, Brian Gerst wrote: >> > > Using strlcpy in this manner could fail if it does larger than byte >> > > copies and they overlap. >> > >> > Why? >> > >> > AFAICT, strlcpy() calls memcpy() and memcpy should handle overlapping >> > buffers just fine. >> >> Are you thinking of memmove? > > I guess I'm trying to find out why don't we have a BIG FAT WARNING over > memcpy saying not to use it with overlapping buffers and larger than > byte sizes. Or maybe this is something everyone, except me, just knows > and that's a "Doh, Boris, of course!". > > Btw, can we still avoid using the temporary buffer and use strncpy() > instead? AFAICT, that does byte copies, from looking at the asm. It's not just chunk size; it's the direction. If the dest starts after the source but overlaps it and you copy forwards, then you can clobber the end of the source before you read it. memmove is specifically intended to avoid this. Would it be possible to just use memmove directly? --Andy -- 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/