From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752081AbdGYVUX (ORCPT ); Tue, 25 Jul 2017 17:20:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50006 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751943AbdGYTT5 (ORCPT ); Tue, 25 Jul 2017 15:19:57 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D37E213A9F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=aarcange@redhat.com Date: Tue, 25 Jul 2017 21:19:52 +0200 From: Andrea Arcangeli To: Michal Hocko Cc: "Kirill A. Shutemov" , Andrew Morton , David Rientjes , Tetsuo Handa , Oleg Nesterov , Hugh Dickins , linux-mm@kvack.org, LKML Subject: Re: [PATCH] mm, oom: allow oom reaper to race with exit_mmap Message-ID: <20170725191952.GR29716@redhat.com> References: <20170724072332.31903-1-mhocko@kernel.org> <20170724140008.sd2n6af6izjyjtda@node.shutemov.name> <20170724141526.GM25221@dhcp22.suse.cz> <20170724145142.i5xqpie3joyxbnck@node.shutemov.name> <20170724161146.GQ25221@dhcp22.suse.cz> <20170725142626.GJ26723@dhcp22.suse.cz> <20170725151754.3txp44a2kbffsxdg@node.shutemov.name> <20170725152300.GM26723@dhcp22.suse.cz> <20170725153110.qzfz7wpnxkjwh5bc@node.shutemov.name> <20170725160359.GO26723@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170725160359.GO26723@dhcp22.suse.cz> User-Agent: Mutt/1.8.3 (2017-05-23) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 25 Jul 2017 19:19:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 25, 2017 at 06:04:00PM +0200, Michal Hocko wrote: > - down_write(&mm->mmap_sem); > + if (tsk_is_oom_victim(current)) > + down_write(&mm->mmap_sem); > free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); > tlb_finish_mmu(&tlb, 0, -1); > > @@ -3012,7 +3014,8 @@ void exit_mmap(struct mm_struct *mm) > } > mm->mmap = NULL; > vm_unacct_memory(nr_accounted); > - up_write(&mm->mmap_sem); > + if (tsk_is_oom_victim(current)) > + up_write(&mm->mmap_sem); How is this possibly safe? mark_oom_victim can run while exit_mmap is running. Even if you cache the first read in the local stack, failure to notice you marked it, could lead to use after free. Or at least there's no comment on which lock should prevent the use after free with the above.