From patchwork Mon Mar 1 12:32:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?546L5pOO?= X-Patchwork-Id: 12109615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E6BFC433E6 for ; Mon, 1 Mar 2021 12:33:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B213664E31 for ; Mon, 1 Mar 2021 12:33:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B213664E31 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=vivo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 47EE86B00C0; Mon, 1 Mar 2021 07:33:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 406EC6B00C2; Mon, 1 Mar 2021 07:33:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F4FF8D0063; Mon, 1 Mar 2021 07:33:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id 161856B00C0 for ; Mon, 1 Mar 2021 07:33:01 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A18D7824999B for ; Mon, 1 Mar 2021 12:32:59 +0000 (UTC) X-FDA: 77871244878.14.9A1A970 Received: from mail-m121143.qiye.163.com (mail-m121143.qiye.163.com [115.236.121.143]) by imf09.hostedemail.com (Postfix) with SMTP id E4E8D600249F for ; Mon, 1 Mar 2021 12:32:52 +0000 (UTC) Received: from vivo-HP-ProDesk-680-G4-PCI-MT.vivo.xyz (unknown [58.250.176.228]) by mail-m121143.qiye.163.com (Hmail) with ESMTPA id 670E2540212; Mon, 1 Mar 2021 20:32:53 +0800 (CST) From: Wang Qing To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Wang Qing Subject: [PATCH] mm: Return -EFAULT if copy_to_user() fails Date: Mon, 1 Mar 2021 20:32:43 +0800 Message-Id: <1614601963-25812-1-git-send-email-wangqing@vivo.com> X-Mailer: git-send-email 2.7.4 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZT0pPSk9JGB1ITk5CVkpNSk9NS0pCTEhNTktVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS0hNSlVLWQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Ohw6ASo*LT8LDxAOHkooAgg6 LjBPCwJVSlVKTUpPTUtKQkxIQk1LVTMWGhIXVQwaFRwKEhUcOw0SDRRVGBQWRVlXWRILWUFZTkNV SU5LVUpMTVVJSUNZV1kIAVlBSk5JSTcG X-HM-Tid: 0a77edc6ef41b038kuuu670e2540212 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E4E8D600249F X-Stat-Signature: pswie5thcaqtxwt3ujzscmwswh9hfaps Received-SPF: none (vivo.com>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=mail-m121143.qiye.163.com; client-ip=115.236.121.143 X-HE-DKIM-Result: none/none X-HE-Tag: 1614601972-22674 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000079, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The copy_to_user() function returns the number of bytes remaining to be copied, but we want to return -EFAULT if the copy doesn't complete. Signed-off-by: Wang Qing --- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index ab51132..a116e56 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1667,7 +1667,7 @@ COMPAT_SYSCALL_DEFINE5(get_mempolicy, int __user *, policy, if (!err && nmask) { unsigned long copy_size; copy_size = min_t(unsigned long, sizeof(bm), alloc_size); - err = copy_from_user(bm, nm, copy_size); + err = copy_from_user(bm, nm, copy_size) ? -EFAULT : 0; /* ensure entire bitmap is zeroed */ err |= clear_user(nmask, ALIGN(maxnode-1, 8) / 8); err |= compat_put_bitmap(nmask, bm, nr_bits);