From: Ian Jackson Subject: Re: [PATCH 09/16] libelf: check nul-terminated strings properly Date: Tue, 4 Jun 2013 16:15:04 +0100 Message-ID: <20910.1144.651512.485359@mariner.uk.xensource.com> References: <1370274111-18377-1-git-send-email-ian.jackson@eu.citrix.com> <1370274111-18377-10-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Matthew Daley Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Matthew Daley writes ("Re: [PATCH 09/16] libelf: check nul-terminated strings properly"): > On Tue, Jun 4, 2013 at 3:41 AM, Ian Jackson wrote: > > @@ -103,10 +103,13 @@ static int print_notes(struct elf_binary *elf, ELF_HANDLE_DECL(elf_note) start, > > - if (0 != strcmp(elf_note_name(elf, note), "Xen")) > > + this_note_name = elf_note_name(elf, note); > > + if (NULL == this_note_name || > > Should be break in this case, not continue, otherwise a invalid large > elf note section will make the loop run for a long time. I think the real problem here is the nested loop. Perhaps we should impose a smallish limit on the size of strings. I've taken the view that looping once per byte of the input image is fine. But I think I this loop (and others like it) can be made to loop O(size_of_input_image^2) times. Changing the continue to break doesn't help because if the attacker puts a nul byte at the end of their image they get to execute the same amount of loop. Ian.