From patchwork Mon Jul 27 17:11:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 11687275 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25FAB138C for ; Mon, 27 Jul 2020 17:03:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E6C3820719 for ; Mon, 27 Jul 2020 17:03:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="RYz1YCi4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6C3820719 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1FB456B0007; Mon, 27 Jul 2020 13:03:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1AF1D6B0008; Mon, 27 Jul 2020 13:03:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF1A76B000A; Mon, 27 Jul 2020 13:03:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id D60226B0007 for ; Mon, 27 Jul 2020 13:03:08 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 91DED180AD81F for ; Mon, 27 Jul 2020 17:03:08 +0000 (UTC) X-FDA: 77084476056.01.field76_15038ea26f62 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 8971810049A4D for ; Mon, 27 Jul 2020 17:02:48 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,anthony.yznaga@oracle.com,,RULES_HIT:30036:30054:30064:30070,0,RBL:141.146.126.78:@oracle.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04y8r133phh85bb54o93m5ba48jjxycijbpmm1saijc68fgs7aermbgm9i1tpk6.rp7qpcggii1jmmbu6prp9td1rxweizd7oz61k4ou7gfnkfargf8qoz7ma8ee6n9.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: field76_15038ea26f62 X-Filterd-Recvd-Size: 4748 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Mon, 27 Jul 2020 17:02:47 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06RH1m1l115287; Mon, 27 Jul 2020 17:02:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=TeNtDqDqIQ7vUEFJe8evTe6FYY6zKZvMIc3ENnPMQc0=; b=RYz1YCi4flsp2nsaalElHjr/hSEq9BFy53s+1DZ+5n+d1AvmCPHXu6sh5Y145WTuFAai HU0TACE1RDbQRpWN8Z8XTQB98axZVsYGs7DSYIoz/h7Klai8PAGqwKRTLDbKImfMts3S P+PsgiBo0fou1y6SAFN9Hpuk/GMdlLoiKrPK69KDT+4x6bJ2UE1bkWLpW+GLclUvh5Dw uGR1Dpzy+80qdnAlIFuEp6v4lk8LH6FusYE8y+/sTrhAFxKylcskhlPSMXWjNYe0nDFJ H5EbxXytrIkHX1d3qQwm16zuK82R9R5HiCQh7J2V0isgUvT+NIRyX4CtBbCtekUKREkg wQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 32hu1j2rah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 27 Jul 2020 17:02:13 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06RGgWKE055548; Mon, 27 Jul 2020 17:02:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 32hu5r9fa8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 27 Jul 2020 17:02:12 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 06RGuWGh111604; Mon, 27 Jul 2020 17:02:12 GMT Received: from ca-qasparc-x86-2.us.oracle.com (ca-qasparc-x86-2.us.oracle.com [10.147.24.103]) by userp3020.oracle.com with ESMTP id 32hu5r9f7r-3; Mon, 27 Jul 2020 17:02:12 +0000 From: Anthony Yznaga To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org Cc: mhocko@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, keescook@chromium.org, gerg@linux-m68k.org, ktkhai@virtuozzo.com, christian.brauner@ubuntu.com, peterz@infradead.org, esyr@redhat.com, jgg@ziepe.ca, christian@kellner.me, areber@redhat.com, cyphar@cyphar.com, steven.sistare@oracle.com Subject: [RFC PATCH 2/5] mm: do not assume only the stack vma exists in setup_arg_pages() Date: Mon, 27 Jul 2020 10:11:24 -0700 Message-Id: <1595869887-23307-3-git-send-email-anthony.yznaga@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1595869887-23307-1-git-send-email-anthony.yznaga@oracle.com> References: <1595869887-23307-1-git-send-email-anthony.yznaga@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9695 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 clxscore=1015 mlxscore=0 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007270117 X-Rspamd-Queue-Id: 8971810049A4D X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In preparation for allowing vmas to be preserved across exec do not assume that there is no prev vma to pass to mprotect_fixup() in setup_arg_pages(). Also, setup_arg_pages() expands the initial stack of a process by 128k or to the stack size limit, whichever is smaller. expand_stack() assumes there is no vma between the vma passed to it and the address to expand to, so check before calling it. Signed-off-by: Anthony Yznaga --- fs/exec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index e6e8a9a70327..262112e5f9f8 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -720,7 +720,7 @@ int setup_arg_pages(struct linux_binprm *bprm, unsigned long stack_shift; struct mm_struct *mm = current->mm; struct vm_area_struct *vma = bprm->vma; - struct vm_area_struct *prev = NULL; + struct vm_area_struct *prev = vma->vm_prev; unsigned long vm_flags; unsigned long stack_base; unsigned long stack_size; @@ -819,6 +819,10 @@ int setup_arg_pages(struct linux_binprm *bprm, else stack_base = vma->vm_start - stack_expand; #endif + if (vma != find_vma(mm, stack_base)) { + ret = -EFAULT; + goto out_unlock; + } current->mm->start_stack = bprm->p; ret = expand_stack(vma, stack_base); if (ret)