Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753395AbcLKM54 (ORCPT ); Sun, 11 Dec 2016 07:57:56 -0500 Received: from mail-bl2nam02on0071.outbound.protection.outlook.com ([104.47.38.71]:57792 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753152AbcLKM5w (ORCPT ); Sun, 11 Dec 2016 07:57:52 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; From: Yury Norov CC: Yury Norov , Arnd Bergmann , "Dr. Philipp Tomsich" , Catalin Marinas , , , LKML , , , , "Joseph S. Myers" , , "Kapoor, Prasun" , Alexander Graf , , , , Andrew Pinski , , Alexey Klimov , , "Zhangjian (Bamvor)" , linux-arm-kernel , Maxim Kuvyrkov , Nathan Lynch , Martin Schwidefsky , , Subject: [PATCH 1/3] mm: move argument checkers of mmap_pgoff() to separated routine Date: Sun, 11 Dec 2016 18:26:40 +0530 Message-ID: <1481461003-14361-2-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481461003-14361-1-git-send-email-ynorov@caviumnetworks.com> References: <1481461003-14361-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.125.246.42] X-ClientProxiedBy: VI1PR0901CA0064.eurprd09.prod.outlook.com (10.167.203.160) To SN1PR07MB2256.namprd07.prod.outlook.com (10.164.47.150) X-MS-Office365-Filtering-Correlation-Id: 74622e91-5cec-4684-cf05-08d421c54ef7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:SN1PR07MB2256; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2256;3:Tl1FQJFPAjmkzDqy5802Wn3QWmhVMULIDyvHCwFY/qQPlrbIfr2QmasorSJdn1j+wrQxkVBlPBzG9YntES0ew23VR6xIYv3hYaikq76+4/Kbab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Uc8V+59t2V20ZWRbjYs/opsIe7Mn3IbE74XqqoRgSkzeO4it9fIC1skyY9MDYat/AydnJ0ms7aKY+qwLOOnOILPuQZsPe0Ojg0lbDqsDaw8xxoh8w3SPjgGdw28Et1KfWag3jBYfWVP3nujwFZT+O+8LvoYawj+24omaHD/Ih2TtKKQlmdczWFZOOHJeNk9BWqMe5YQgaUaJnApOEpjrs7OfUn9aJoDpr2ZoJEo3BzTdN9adTI54E/LumfIhEA/Jtzda6LF+2MsaiV1rzS93ZF++25tpXD2NxKm/MGyLYIJUS+V16AWGXFpwofHXoFkd2gPuHcA2Ng2ibqL3Snn9zBQkITgySmZxxAPN0sTrXo6h82TpMGaIfByhU7qVytfFoqwh4grbZFrSk5+iDvrmnf+528pNqRd1EZSI1SVH9bf1G6VZ9bv5Zd+9/IWQjwyBHNdYYPQG7hctKzkSmtOjE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123564025)(20161123560025)(20161123562025)(20161123555025)(6072148);SRVR:SN1PR07MB2256;BCL:0;PCL:0;RULEID:;SRVR:SN1PR07MB2256; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2256;4:rabgJFtBJMf9KYMkm2wUAKzOKt+AVW61fNWiddElfCXTHtJGnHm9s5hadeBJUd2H4SMPhulMi8WwTo36NwSr43eAkMx4T/05kK3BRkp1kJLTmfY8xW0edoTQZs9KGpCjOmEX/V8BxNFn8lhAISEzmQvjuZlCGiHxnf5M3VXbUimuvIxfUa65ayjbt5gVhjfkW+FlaBHrlGVP7wzvhoz9yrxxdHLHiD2RJDzk+hDWifhrZvetkQUy7X0xySg0HBRUhnetOko/8psf/C4iZlLAtHKvzuFIEbni9wF7dCT/P07ymFHfE0DZGSXdHI/DWwLKnn26IPXwZVhFLPHf2pWZW4iRCLO03ASrOLva8foMVDKHwVTXR6ljseMtcY928CfNlrSUg2QIC5YlyO868GXjCpt997iHOUY4XcFgERYjdR8lRWnZNWr0qUB/gznZdBYZSyOWpcpVTIIJPi8Kki+61iJRzQchv1BrUUKy7VVSgG1Ukxi+ct01LYepcIO2IYR62jLPU93mTbZUPjNkED4Cw+Yipf5jXtRS5BwKMMahirVjHOcRI+N0jMF5+9l+hJQQGefVS0TXug+IIA119KtmEw== X-Forefront-PRVS: 0153A8321A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(39450400003)(39410400002)(39840400002)(189002)(199003)(2906002)(42186005)(109986004)(8676002)(4326007)(105586002)(106356001)(81156014)(7736002)(81166006)(48376002)(50226002)(97736004)(76506005)(305945005)(92566002)(50986999)(5660300001)(6496003)(6486002)(47776003)(101416001)(189998001)(39060400001)(33646002)(50466002)(5003940100001)(1671002)(7416002)(36756003)(6116002)(66066001)(76176999)(3846002)(38730400001)(6666003)(68736007)(5009440100003)(110136003)(2950100002)(266003);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR07MB2256;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR07MB2256;23:k/joBhIDz1GXkJglGQVSE2la0d0YGaiVk8iTXZtMV?= =?us-ascii?Q?QWaQQIU9xJEcB0MBocPufyvqNzBGjfTXL3ag4HP+dIG+lmUZt7wzZrOhX6Ba?= =?us-ascii?Q?pFMbgDG8mQmHC3+rE/ugWGjjCoiUaPBxUkpdIHMDf5Svil6DKGmTkDL4Szfd?= =?us-ascii?Q?mQ5ThcOKE5DpxCrdFspnep+mdYEBWuzgkd2HniI89JSj9nWumUGCPeX0eZVV?= =?us-ascii?Q?v7BAZaJpMtLr/une9kDclXQOM4Yrg7KbuREf5jiCOEzNUDdffgR51SY+r6BU?= =?us-ascii?Q?xnH5mv6yJaX1zLJzEPwlggLIOTXbBjxM29rk78H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ddOM+mvL5e45np/IDah37D3Hc6VMW+i4lQmDLo/pGw3/uxbQFwtA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2256;6:Z515+1vymg1uc1GdLRusjw/y/U8+wF8o+AsTXQSuLxD92p0HWPimwYr26xK5sPvxLftwEHVrxkaT8UCVNLVtFK8TLesgJtOFhTKpTfkySoRiigA0kNfvgN/21T/S29xKphi/Q5odVlm7OD0JGbuK+Os3WrmZ0tY0sK6WdiBHBwCX35KW9D09qoLIqEMhTiSIZVoCK1D1NSJifSi8TbNkNTBpZoKa+cOs85UBwDGkwugAud9s8b1NaNrGlIT15eEYl8XvHR/+pyjZaGmPBG/oxGVT9IZQ+IHnIyK9300om5IRbPw6UN38WpHUhQwSM1P10T4Wn6B+E4o93Dwd1lmrJiWWZGOYcNue741Q0it85ckzMnennMb4I4jaCUBv1a3wHbHjfsjegaEUd4BReCD8NzSFj21k9tc25e7lhkrzcuc=;5:5jQBvvixGPs/Ft3Kwn8C+7aYXMJfFef7lm6xMqfUZ7zpA6xewEJEElNg187soN1bD+yc/BZMM0vOfD/UYpEyIJyaKf5faVOJ//6vT/vxnabRxxJQaUi8XLzvX6Q9gGIL+bh7ccPCutNEI2mDNhbzJ9umxWfmzIimGFDtV8m8/cw=;24:Nvl4kDCZEnaMhmHcQM7Iiek7dnDsj1/hY8nfTJk1XhpfGRcMRmXQ2nQcFcsG++fXqbL8JFh4SpPUx6tiYqLDg4+9lNtrfASiPKJ/wEFRMKA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2256;7:FNwX7XUTlzvorqkIVosBjA0iBw/bTfeHz22dK3aphKlhRqP+MX89LD9APSveAOri00SYcVpgW22Z/nqVOdczWZ60L9A0uCAznU5/T/nUrNf9neXCLAgRFnnJek83dedh0ijKVWAKcXfRDgAVFv0bIbOV06jk1KHxP/eQMozXX3wp2kihUnC7Xjb/WB9szM2ktLa1E2yx5Ce+yw35MAuiG00Gv+5/dcXadvo8XRZbtgSFCj1lH6rzAfagYxhsSTK4AraIlgTlnNdD4OfV/jXzrzNdgimaaruS376SxdhgOEn1UZgkAGYGQApeLHxQVleXYXldbalz/IR6yrgAqW9DTN0QNfyNsrSrHawzHZEKx+mMjhqmReGm28RuiERA0dPZ/uCSAxphLrpyvUU4Go0OMdm4ECkv20q86KdUvOG3MNcNBr0mzGSMzx/cWustI5vScuL2f+MPvlgUuSEbikivuQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2016 12:57:46.1281 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB2256 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1965 Lines: 68 Signed-off-by: Yury Norov --- mm/mmap.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 1af87c1..fc1c943 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1455,12 +1455,12 @@ unsigned long do_mmap(struct file *file, unsigned long addr, return addr; } -SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, - unsigned long, prot, unsigned long, flags, - unsigned long, fd, unsigned long, pgoff) +static int mmap_pgoff_prepare(struct file **f, unsigned long *l, + unsigned long *fl, unsigned long fd) { - struct file *file = NULL; - unsigned long retval; + struct file *file = *f; + unsigned long flags = *fl; + unsigned long len = *l; if (!(flags & MAP_ANONYMOUS)) { audit_mmap_fd(fd, flags); @@ -1469,9 +1469,10 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, return -EBADF; if (is_file_hugepages(file)) len = ALIGN(len, huge_page_size(hstate_file(file))); - retval = -EINVAL; - if (unlikely(flags & MAP_HUGETLB && !is_file_hugepages(file))) - goto out_fput; + if (unlikely(flags & MAP_HUGETLB && !is_file_hugepages(file))) { + fput(file); + return -EINVAL; + } } else if (flags & MAP_HUGETLB) { struct user_struct *user = NULL; struct hstate *hs; @@ -1497,8 +1498,23 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); + *f = file; + *l = len; + *fl = flags; + return 0; +} + +SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags, + unsigned long, fd, unsigned long, pgoff) +{ + struct file *file = NULL; + unsigned long retval; + int err = mmap_pgoff_prepare(&file, &len, &flags, fd); + if (err) + return err; + retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff); -out_fput: if (file) fput(file); return retval; -- 2.7.4