From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751538AbcGMRBg (ORCPT ); Wed, 13 Jul 2016 13:01:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58849 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750913AbcGMRBf (ORCPT ); Wed, 13 Jul 2016 13:01:35 -0400 Date: Wed, 13 Jul 2016 19:00:49 +0200 From: Oleg Nesterov To: Kees Cook Cc: Andrew Morton , Hector Marco-Gisbert , Ismael Ripoll Ripoll , Alexander Viro , "Kirill A. Shutemov" , Chen Gang , Michal Hocko , Konstantin Khlebnikov , Andrea Arcangeli , Andrey Ryabinin , "linux-fsdevel@vger.kernel.org" , Linux-MM , LKML Subject: Re: [PATCH 2/2] mm: refuse wrapped vm_brk requests Message-ID: <20160713170048.GA24553@redhat.com> References: <1468014494-25291-1-git-send-email-keescook@chromium.org> <1468014494-25291-3-git-send-email-keescook@chromium.org> <20160711122826.GA969@redhat.com> <20160712133942.GA28837@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 13 Jul 2016 17:00:31 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/12, Kees Cook wrote: > > On Tue, Jul 12, 2016 at 9:39 AM, Oleg Nesterov wrote: > > > > I tried to say that, with or without this change, sys_brk() should check > > for overflow too, otherwise it looks buggy. > > Hmm, it's not clear to me the right way to fix sys_brk(), but it looks > like my change to do_brk() would catch the problem? How? Once again, afaics nothing bad can happen, sys_brk() will silently fail, just the code looks wrong anyway. Suppose that newbrk == 0 due to overflow, then both if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE)) goto out; and if (do_brk(oldbrk, newbrk-oldbrk) < 0) goto out; look buggy. find_vma_intersection(start_addr, end_addr) expects that start_addr < end_addr. Again, we do not really care if it returns NULL or not, and newbrk == 0 just means it will certainly return NULL if there is something above oldbrk. Just looks buggy/confusing. do_brk(0 - oldbrk) will fail and this is what we want. But not because your change will catch the problem, PAGE_ALIGNE(-oldbrk) won't necessarily overflow. However, -oldbrk > TASK_SIZE so get_unmapped_area() should fail. Nevermind, this is almost off-topic, so let me repeat just in case that both patches look good to me. Oleg.