Received: by 10.213.65.68 with SMTP id h4csp2245076imn; Thu, 5 Apr 2018 11:28:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx48ImgevXIt37GC7Yx4p5VGPZpmWhdbQRRxmcPUiXlRvRNzQHYSFQGMlRxK75S95hJRid2bC X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr23986150plc.214.1522952896241; Thu, 05 Apr 2018 11:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522952896; cv=none; d=google.com; s=arc-20160816; b=A126XL7zxC2cUHO1lYjOiK9dLZlcgto0OmZXDto/zw7DuLHLnulUikbsDCnlKZkcXo 8sZEEVMYyCOQgH6bkZnNx2bQWpNTS69SgL3ij+ywlC5gHAtLpki0DS5s+biUEvqE2OMz U2tYdXkP8ZGDg1aQ1CwlzMx0/cZIE4eeRiZVdydp8N8y7JMEvbOtQwKNPs0x0nOi4lQQ N4CTz9pVgY+r/F12pHTfe+PVbxrPEG3mzyHsibjqsKifMrrg9z0zC2AZhwOO9Wl09q3V I3Gx3k5N58N10ZQ3BlvnbZiwEQ1oUIvYPj3uCYYe8cruT6EQ8tWPbQFAFinDHdn8gfgu lHiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=cDTgJkUfavbVXSJNPyA4srwlAlRZmB3N6maONIsR+H0=; b=GNyWP2FyEiizVqSsuZLv8khhW6FSYGKPooM0MEmMA4XjoIvLu5U7PApbNUSHerxroN lAqRGtTcd2CEPNHknYT9TgNtHRwBYB5yQ6vravq4KZU4tHbsv6Qs/LZ73Wik1LMHV6fc xs1XncGQLUeXwTuCLUfZXp4NSU1NvglkPz91liLxD6ONvVYFwUAsoCYMWx1AW2E2KhJi laqUUzqMgY6o1V8lYRpFLPs9XxdPfrf5Xc0OESmdLEWHUyTuyiW9KgeDq8tG152XsImt tCYaItJ0waEY9fX85zYFxufhiEj5rsPhNM3lPyqGPxPDzum2FpYj/ELEFRxzC4PSv4iJ s4mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IIxw4MH8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay5-v6si6147058plb.88.2018.04.05.11.28.01; Thu, 05 Apr 2018 11:28:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IIxw4MH8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751593AbeDES0z (ORCPT + 99 others); Thu, 5 Apr 2018 14:26:55 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:40932 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751417AbeDES0y (ORCPT ); Thu, 5 Apr 2018 14:26:54 -0400 Received: by mail-wm0-f67.google.com with SMTP id x4so9705318wmh.5 for ; Thu, 05 Apr 2018 11:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=cDTgJkUfavbVXSJNPyA4srwlAlRZmB3N6maONIsR+H0=; b=IIxw4MH8QCx839CQS6TsZE33kpECmaXbM+bLUGSH0Y+p4cAZRlsOpyow2M9GhNpA6a nPton1GOPrSyGOZFww1a+0SG3YQoS0sRepWKqgRIusbdLeNzOkRZG62aa+6mkyeeRTUS npoUJRGGeqbCMHWQembrlxKvGsPjFJxmyVJzLDiP/4guSmziInWQqHpdjtSo5seiOmcB nEGRa+bKl6KEl9Pi2u3mMeo3Q5CfIMdv6QxCQ1wCXavxxGUXkvLoJzkPDVr7Zhpw0LHm acJd70xAH5HJoLGvETOfZd351dDZrJ4XhNjJ/dZA5567wa1kzLJCBoDEWtwr/Nq+Pay5 p6og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=cDTgJkUfavbVXSJNPyA4srwlAlRZmB3N6maONIsR+H0=; b=PZVKuvfePdjlJWzNTQYvrcIij3Fv8svcT/xKlguvujU+6F+cOUnmmlUxOLFc9fdArm GQou6WzeQQBCcAWUiLFdXpifdxaJB0Mj+4CE4o/16jLMQgMPCRPkpBrxhj1sq+0Uiw3Y X/nXchIWd4OPwcKMP74u2pDexVsF5nC3bw8PeeDJ3XMKy8TmHOpDRoRbMTYOzE1GnwtG Ml1n8lIGEcHhDYlVX/1w0mvPcEckenfJxsqJkmj49F1dKZPZ8M5KBUvUk9QH4+vYa+n+ HbSGafQnJS+KUBi62pNjwKCFVMcarmuSAAN3LaLDIFz4TDu0aUhMUKNDtyxwz46qjenL LBpw== X-Gm-Message-State: AElRT7FkKXwKGozyCUvuv4ItWv5x3zsIjCKOxvQKoK2cLvjO3VBCx6gH 2CoptelsC6MMHX+xsPRl+JY= X-Received: by 10.46.154.213 with SMTP id p21mr14382442ljj.59.1522952812791; Thu, 05 Apr 2018 11:26:52 -0700 (PDT) Received: from uranus.localdomain ([5.18.102.224]) by smtp.gmail.com with ESMTPSA id p1sm1407883lje.56.2018.04.05.11.26.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Apr 2018 11:26:51 -0700 (PDT) Received: by uranus.localdomain (Postfix, from userid 1000) id 3C48046093D; Thu, 5 Apr 2018 21:26:51 +0300 (MSK) Date: Thu, 5 Apr 2018 21:26:51 +0300 From: Cyrill Gorcunov To: LKML Cc: Michal Hocko , Randy Dunlap , Andrey Vagin , Andrew Morton , Pavel Emelyanov , Michael Kerrisk , Yang Shi Subject: [PATCH v2] prctl: Deprecate non PR_SET_MM_MAP operations Message-ID: <20180405182651.GM15783@uranus.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An ability to manipulate mm_struct fields was introduced in sake of CRIU in first place. Later we provide more suitable and safe operation PR_SET_MM_MAP where all fields to be modifed are passed in one structure which allows us to make more detailed verification. Still old interface remains present for compatibility reason though CRIU itself already switched to PR_SET_MM_MAP on its own long ago. Googling didn't reveal some other users of this operation so I think it should be safe to remove this interface. v2: - Improve warning message - Drop redundant args check CC: Andrey Vagin CC: Andrew Morton CC: Pavel Emelyanov CC: Michael Kerrisk CC: Yang Shi CC: Michal Hocko Signed-off-by: Cyrill Gorcunov --- kernel/sys.c | 151 ----------------------------------------------------------- 1 file changed, 2 insertions(+), 149 deletions(-) Index: linux-ml.git/kernel/sys.c =================================================================== --- linux-ml.git.orig/kernel/sys.c +++ linux-ml.git/kernel/sys.c @@ -2053,163 +2053,16 @@ static int prctl_set_mm_map(int opt, con } #endif /* CONFIG_CHECKPOINT_RESTORE */ -static int prctl_set_auxv(struct mm_struct *mm, unsigned long addr, - unsigned long len) -{ - /* - * This doesn't move the auxiliary vector itself since it's pinned to - * mm_struct, but it permits filling the vector with new values. It's - * up to the caller to provide sane values here, otherwise userspace - * tools which use this vector might be unhappy. - */ - unsigned long user_auxv[AT_VECTOR_SIZE]; - - if (len > sizeof(user_auxv)) - return -EINVAL; - - if (copy_from_user(user_auxv, (const void __user *)addr, len)) - return -EFAULT; - - /* Make sure the last entry is always AT_NULL */ - user_auxv[AT_VECTOR_SIZE - 2] = 0; - user_auxv[AT_VECTOR_SIZE - 1] = 0; - - BUILD_BUG_ON(sizeof(user_auxv) != sizeof(mm->saved_auxv)); - - task_lock(current); - memcpy(mm->saved_auxv, user_auxv, len); - task_unlock(current); - - return 0; -} - static int prctl_set_mm(int opt, unsigned long addr, unsigned long arg4, unsigned long arg5) { - struct mm_struct *mm = current->mm; - struct prctl_mm_map prctl_map; - struct vm_area_struct *vma; - int error; - - if (arg5 || (arg4 && (opt != PR_SET_MM_AUXV && - opt != PR_SET_MM_MAP && - opt != PR_SET_MM_MAP_SIZE))) - return -EINVAL; - #ifdef CONFIG_CHECKPOINT_RESTORE if (opt == PR_SET_MM_MAP || opt == PR_SET_MM_MAP_SIZE) return prctl_set_mm_map(opt, (const void __user *)addr, arg4); #endif - if (!capable(CAP_SYS_RESOURCE)) - return -EPERM; - - if (opt == PR_SET_MM_EXE_FILE) - return prctl_set_mm_exe_file(mm, (unsigned int)addr); - - if (opt == PR_SET_MM_AUXV) - return prctl_set_auxv(mm, addr, arg4); - - if (addr >= TASK_SIZE || addr < mmap_min_addr) - return -EINVAL; - - error = -EINVAL; - - down_write(&mm->mmap_sem); - vma = find_vma(mm, addr); - - prctl_map.start_code = mm->start_code; - prctl_map.end_code = mm->end_code; - prctl_map.start_data = mm->start_data; - prctl_map.end_data = mm->end_data; - prctl_map.start_brk = mm->start_brk; - prctl_map.brk = mm->brk; - prctl_map.start_stack = mm->start_stack; - prctl_map.arg_start = mm->arg_start; - prctl_map.arg_end = mm->arg_end; - prctl_map.env_start = mm->env_start; - prctl_map.env_end = mm->env_end; - prctl_map.auxv = NULL; - prctl_map.auxv_size = 0; - prctl_map.exe_fd = -1; - - switch (opt) { - case PR_SET_MM_START_CODE: - prctl_map.start_code = addr; - break; - case PR_SET_MM_END_CODE: - prctl_map.end_code = addr; - break; - case PR_SET_MM_START_DATA: - prctl_map.start_data = addr; - break; - case PR_SET_MM_END_DATA: - prctl_map.end_data = addr; - break; - case PR_SET_MM_START_STACK: - prctl_map.start_stack = addr; - break; - case PR_SET_MM_START_BRK: - prctl_map.start_brk = addr; - break; - case PR_SET_MM_BRK: - prctl_map.brk = addr; - break; - case PR_SET_MM_ARG_START: - prctl_map.arg_start = addr; - break; - case PR_SET_MM_ARG_END: - prctl_map.arg_end = addr; - break; - case PR_SET_MM_ENV_START: - prctl_map.env_start = addr; - break; - case PR_SET_MM_ENV_END: - prctl_map.env_end = addr; - break; - default: - goto out; - } - - error = validate_prctl_map(&prctl_map); - if (error) - goto out; - - switch (opt) { - /* - * If command line arguments and environment - * are placed somewhere else on stack, we can - * set them up here, ARG_START/END to setup - * command line argumets and ENV_START/END - * for environment. - */ - case PR_SET_MM_START_STACK: - case PR_SET_MM_ARG_START: - case PR_SET_MM_ARG_END: - case PR_SET_MM_ENV_START: - case PR_SET_MM_ENV_END: - if (!vma) { - error = -EFAULT; - goto out; - } - } - - mm->start_code = prctl_map.start_code; - mm->end_code = prctl_map.end_code; - mm->start_data = prctl_map.start_data; - mm->end_data = prctl_map.end_data; - mm->start_brk = prctl_map.start_brk; - mm->brk = prctl_map.brk; - mm->start_stack = prctl_map.start_stack; - mm->arg_start = prctl_map.arg_start; - mm->arg_end = prctl_map.arg_end; - mm->env_start = prctl_map.env_start; - mm->env_end = prctl_map.env_end; - - error = 0; -out: - up_write(&mm->mmap_sem); - return error; + pr_warn_once("PR_SET_MM_* has been removed. Use PR_SET_MM_MAP instead\n"); + return -EINVAL; } #ifdef CONFIG_CHECKPOINT_RESTORE