Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752633AbdDRF3s (ORCPT ); Tue, 18 Apr 2017 01:29:48 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51609 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750759AbdDRF3q (ORCPT ); Tue, 18 Apr 2017 01:29:46 -0400 From: Anshuman Khandual To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: n-horiguchi@ah.jp.nec.com, akpm@linux-foundation.org Subject: [PATCH V3] mm/madvise: Move up the behavior parameter validation Date: Tue, 18 Apr 2017 10:58:44 +0530 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170413092008.5437-1-khandual@linux.vnet.ibm.com> References: <20170413092008.5437-1-khandual@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17041805-0048-0000-0000-0000021D8F80 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17041805-0049-0000-0000-000047CAB87B Message-Id: <20170418052844.24891-1-khandual@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704180047 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1762 Lines: 61 The madvise_behavior_valid() function should be called before acting upon the behavior parameter. Hence move up the function. This also includes MADV_SOFT_OFFLINE and MADV_HWPOISON options as valid behavior parameter for the system call madvise(). Signed-off-by: Anshuman Khandual --- Changes in V3: Moved the madvise_inject_error() function down which will make sure that the boundary conditions are checked for address and length arguments as per Naoya. Changes in V2: Added CONFIG_MEMORY_FAILURE check before using MADV_SOFT_OFFLINE and MADV_HWPOISONE constants. mm/madvise.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index efd4721..721dd6f 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -694,6 +694,10 @@ static int madvise_inject_error(int behavior, #endif case MADV_DONTDUMP: case MADV_DODUMP: +#ifdef CONFIG_MEMORY_FAILURE + case MADV_SOFT_OFFLINE: + case MADV_HWPOISON: +#endif return true; default: @@ -767,10 +771,6 @@ static int madvise_inject_error(int behavior, size_t len; struct blk_plug plug; -#ifdef CONFIG_MEMORY_FAILURE - if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE) - return madvise_inject_error(behavior, start, start + len_in); -#endif if (!madvise_behavior_valid(behavior)) return error; @@ -790,6 +790,11 @@ static int madvise_inject_error(int behavior, if (end == start) return error; +#ifdef CONFIG_MEMORY_FAILURE + if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE) + return madvise_inject_error(behavior, start, start + len_in); +#endif + write = madvise_need_mmap_write(behavior); if (write) { if (down_write_killable(¤t->mm->mmap_sem)) -- 1.8.5.2