Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751526AbdG0G1K (ORCPT ); Thu, 27 Jul 2017 02:27:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45307 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750910AbdG0G1I (ORCPT ); Thu, 27 Jul 2017 02:27:08 -0400 From: Mike Rapoport To: Andrew Morton Cc: Andrea Arcangeli , "Dr. David Alan Gilbert" , Pavel Emelyanov , linux-mm , lkml , Mike Rapoport , stable@vger.kernel.org Subject: [PATCH] userfaultfd_zeropage: return -ENOSPC in case mm has gone Date: Thu, 27 Jul 2017 09:26:59 +0300 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 x-cbid: 17072706-0040-0000-0000-000003C7D9A4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17072706-0041-0000-0000-000025C55E56 Message-Id: <1501136819-21857-1-git-send-email-rppt@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-07-27_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707270104 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1043 Lines: 33 In the non-cooperative userfaultfd case, the process exit may race with outstanding mcopy_atomic called by the uffd monitor. Returning -ENOSPC instead of -EINVAL when mm is already gone will allow uffd monitor to distinguish this case from other error conditions. Cc: stable@vger.kernel.org Fixes: 96333187ab162 ("userfaultfd_copy: return -ENOSPC in case mm has gone") Signed-off-by: Mike Rapoport --- Unfortunately, I've overlooked userfaultfd_zeropage when I updated userfaultd_copy :( fs/userfaultfd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index cadcd12a3d35..2d8c2d848668 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1643,6 +1643,8 @@ static int userfaultfd_zeropage(struct userfaultfd_ctx *ctx, ret = mfill_zeropage(ctx->mm, uffdio_zeropage.range.start, uffdio_zeropage.range.len); mmput(ctx->mm); + } else { + return -ENOSPC; } if (unlikely(put_user(ret, &user_uffdio_zeropage->zeropage))) return -EFAULT; -- 2.7.4