From patchwork Thu Oct 4 21:14:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10626759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31DE316B1 for ; Thu, 4 Oct 2018 21:15:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 213AF293B1 for ; Thu, 4 Oct 2018 21:15:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14A48295AC; Thu, 4 Oct 2018 21:15:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A007293B1 for ; Thu, 4 Oct 2018 21:15:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94F766B0010; Thu, 4 Oct 2018 17:15:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8FE626B0266; Thu, 4 Oct 2018 17:15:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 814AD6B0269; Thu, 4 Oct 2018 17:15:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 45E116B0010 for ; Thu, 4 Oct 2018 17:15:20 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id d22-v6so7341590pfn.3 for ; Thu, 04 Oct 2018 14:15:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=74647uHGjqR09NCtkBRofAJku/T/0sqkgzrbFs8/X7g=; b=BF1qiRJ3Aonw6GxqOfuR6d56lgjoyWG8/y0Sjt2i5yadtQDxbjtWkDG6Xcul35JWWr Gb7dRn9g103y768Q30A5BbXNgxemRBnNFWxr+rGxw0h2vfoUSYy1pwFH1zo85StpRIyp lI2fpmP78zw6zW+fgd15UrLOJQiGqU/xMC3mqrckYQ3n9UGbLfQFU8Uh2dDiiwdfQZxs 8GYasyLcj2Qg3ZX2wIT/jHPohoi0w+6cVGYaNm/fcQBwEm6kb6iEYwfGjr8zRck7nLH1 UwNMGa64UwPz9dA58K7inbT0g8i9GbXH4fCk8KFeTsethn0d5fq/7AiuTDh6BIY/yPN7 1PWA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: ABuFfogCJwPfmaRotVUmtG2Y+0QCUdcG7vzrlPCWnQUqs+tXgplzTXc0 uzovglbEXRjSbLhvOdyu8+tKVH67HKbUoKnWpw0Gjev3+A1eWxvqKnPwJtNDnNnAr7+296DdvXH wx2+oQuf5pMcD72WJz+FS6+rGTBV6m/Gn25eeJUQqaeh0KORshm9yew0lBJOwpmfe3A== X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr8326473plq.334.1538687719966; Thu, 04 Oct 2018 14:15:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV61xoBbG6qVbH1DpimR4TS2GT+CPm09TpnDmzE+62V+MD4YszwIywT9mv1NCdig08a5ZBy7+ X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr8326438plq.334.1538687719269; Thu, 04 Oct 2018 14:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538687719; cv=none; d=google.com; s=arc-20160816; b=fJmJdTny6mxk/j8EuJfTLURZvFT12dKz0kNOtjibB67liCfvR12GHHjyxvrM1W8P32 DKGe44tK8V/5AvvqDPEH/cnKH7uoJK3V0GUdc6einrOse/ahei+E5NX5YtzjEuTzgsEy Jnz0syRb7XzxFefXiACbnF8AygjuK5Begcv5mFGkUyb34JSpu0xiLitRRJFept64i3R3 O4ln/BPbKbmg3v+MFayD2KR0beckdEvpCZfFPdHkdUPVspCiIkKSVA0NtpeAVkRTK60v 4fHBNw9QsHONpqpQxrlyZ3NxK7w0Hu0l4hd6RJCPA7emBtysngIbj6T3auSWqH3RbT+M 0BmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=74647uHGjqR09NCtkBRofAJku/T/0sqkgzrbFs8/X7g=; b=GKpg9k+CuFMaeJsiOJ6MOQe7+vfHHdEWfh1GVue7lXTessHCcl4aeEetjExNkdvW1w DTxppV7j1LQzaQuHMeGlVCqyoJ0BPhD2D+WukXbp55B7rjWDuqhTuWb5MVlhxVeuthnx giehc8aaEFcAeXKpsATf3A5ruiEKA7LAxmOM4h50Ta0o6mN9ebgML5387WG/VdatnzOH HeQm15YxAkL46lHn16yiT4v91hkRpHr5o+hLRx8Xyv5dIrhFAuJJ/aiDhKzZlOCTXlG1 EXyPjRmyvXuyUQ+5wryECpIpvn9otOGEzZ9rwmhl1MR/8OgIYJx5hRdS08Me7BhUxUi5 q0sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id s17-v6si4940902pgm.317.2018.10.04.14.15.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 14:15:19 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04390;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0T9zY.5M_1538687672; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T9zY.5M_1538687672) by smtp.aliyun-inc.com(127.0.0.1); Fri, 05 Oct 2018 05:14:40 +0800 From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, mhocko@kernel.org, willy@infradead.org, ldufour@linux.vnet.ibm.com, colin.king@canonical.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2 -mm] mm: brk: fix unsigned compare against 0 issue Date: Fri, 5 Oct 2018 05:14:31 +0800 Message-Id: <1538687672-17795-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Static analysis reported unsigned compare against 0 issue according to Colin Ian King. Defined an int temp variable to check the return value of __do_munmap(). Reported-by: Colin Ian King Cc: Vlastimil Babka Cc: Kirill A. Shutemov Cc: Michal Hocko Cc: Matthew Wilcox Cc: Laurent Dufour Cc: Andrew Morton Signed-off-by: Yang Shi --- Andrew, this should be able to be folded into the original patch. mm/mmap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 68dc4fb..c78f7e9 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -242,17 +242,18 @@ static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long * __do_munmap() may downgrade mmap_sem to read. */ if (brk <= mm->brk) { + int ret; /* * mm->brk need to be protected by write mmap_sem, update it * before downgrading mmap_sem. * When __do_munmap fail, it will be restored from origbrk. */ mm->brk = brk; - retval = __do_munmap(mm, newbrk, oldbrk-newbrk, &uf, true); - if (retval < 0) { + ret = __do_munmap(mm, newbrk, oldbrk-newbrk, &uf, true); + if (ret < 0) { mm->brk = origbrk; goto out; - } else if (retval == 1) + } else if (ret == 1) downgraded = true; goto success; } From patchwork Thu Oct 4 21:14:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10626761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09E3517E0 for ; Thu, 4 Oct 2018 21:15:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF408293F7 for ; Thu, 4 Oct 2018 21:15:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3749295BA; Thu, 4 Oct 2018 21:15:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B73293F7 for ; Thu, 4 Oct 2018 21:15:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C82E16B0269; Thu, 4 Oct 2018 17:15:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C338A6B026A; Thu, 4 Oct 2018 17:15:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B231D6B026B; Thu, 4 Oct 2018 17:15:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 6FCEF6B0269 for ; Thu, 4 Oct 2018 17:15:29 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id v88-v6so7313251pfk.19 for ; Thu, 04 Oct 2018 14:15:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=VvmIHtPAYZ1LeS/YZsTd9I9vDsz1OnTtk8G+kVjmRW4=; b=pkdJyGQ82dQ92c4+eS6LSKCLrdIpfIWRTLjGr7kNa9T01ZwGAQ+bTMc75H+LBtRHYj gbm32YsxtDMEU4JfAQCoV3SzvOJ9Enadx7RFUvPAFWtu+FIMMOZcXnO2Mrs8sQnYTIdW FZI52tpuUxUX8g307DgBZgqDX7a/OINCix74tOsePAK8i0vvULDAccEKKQxkdfrycVPZ q2e7bmOYkS9MW+OMsBAWDR9n/AniSa8O0hVBsrXBAhyAiQH6Yfkq7+2BAUFyLF/jXdKu Vkjgm6GCyJ6YsInbeod2LHj5C6eLzMRWPAwrEWWCt7vVEvixaFBAAtxWAXQ9QFJSBQY8 7m4w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: ABuFfog+6efosoA+YX5Y3Cltl8+ZUkbgWEKOLiMyHPl5zwAnqTdyZ1oJ vM8XgtQ8rMnytfx9aYKs5v2G/xl4AC2Gof69bCp0xP39nqtqA6ytplkOO9Gtr5kSq9LEETqSKas ogGWCHVxfr7Qo149sN/di2vHAPZ67QW7HG+ccmc3cthSkSPN/cd0oKFpNy4koMESd9w== X-Received: by 2002:a63:1148:: with SMTP id 8-v6mr7460840pgr.172.1538687729132; Thu, 04 Oct 2018 14:15:29 -0700 (PDT) X-Google-Smtp-Source: ACcGV61diSo8yA3i86YswViKv/7Sj9XjM1YyqzAHSMXxs4OCmT3ZHfw+9a0thzLy2bP+26aNr0q0 X-Received: by 2002:a63:1148:: with SMTP id 8-v6mr7460793pgr.172.1538687728165; Thu, 04 Oct 2018 14:15:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538687728; cv=none; d=google.com; s=arc-20160816; b=icvSQxfV9T0RcEcRcVBj7iw+4EadgspjxV9pD+OeqeLLfSbkDrBXCtQ2wwivrdcX8A pu5NbM1DI1w2kV+XKXMbOQlvr45l37sqJFfbjtaOydbRjj5UMkNeGcZf+H7mCaK0xB9J Ka4W+nM8ygDoHX7XI3OtUmd5h84eO1aabGv90Tu8kGRll3wguguPwpzvDd7Os2/prxFV ALXSjESPj5XtV7CKEIuYzMBta9PhN51a4bv4vTf1JI1whnBfNw7NuiJDlPAY3MzmW4bg jGkF7S9hzcvdQ+oU3eULq2iit5wjWLGS6lMC2hqayrcQtX0hyiHDy7UQqjClntr2N2I5 SOEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=VvmIHtPAYZ1LeS/YZsTd9I9vDsz1OnTtk8G+kVjmRW4=; b=W/AIzNjiT7ThS7dCVQ+UrWHy+nKKDcuLUDfznWkHWeiCB1JCuD4pg7rhThHTzhgL2W pVaVeJ+OqYTwut+6l7c2t9+BSaNqtAEa4B78MfqzEJWKPwQbVpTLItNlO7x9p1d/EPi3 BQ2Qrm3R5TT8vIvSmaP6G7b+bVPw/uHCC6YojfbRz2tdLSPi682UB5UUqpH0nNDoBz4h SS1u87urE0kvlGPRc0GyoF7yWzE2WQxAya03RMqVlBJf3PnalIqud0v1AoOE/0nzy5do BwB099ECEP2FW2MIkuG5GFi0eleDW7kgdp48w4pRqkdFXRpnYI0XfrcDOihYpEGmkBGu rCKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id 20-v6si6146295pfk.287.2018.10.04.14.15.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 14:15:28 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04389;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0T9zY.5M_1538687672; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T9zY.5M_1538687672) by smtp.aliyun-inc.com(127.0.0.1); Fri, 05 Oct 2018 05:14:40 +0800 From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, mhocko@kernel.org, willy@infradead.org, ldufour@linux.vnet.ibm.com, colin.king@canonical.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2 -mm] mm: mremap: fix unsigned compare against 0 issue Date: Fri, 5 Oct 2018 05:14:32 +0800 Message-Id: <1538687672-17795-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538687672-17795-1-git-send-email-yang.shi@linux.alibaba.com> References: <1538687672-17795-1-git-send-email-yang.shi@linux.alibaba.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Static analysis reported unsigned compare against 0 issue according to Colin Ian King. Defined an int temp variable to check the return value of __do_munmap(). Reported-by: Colin Ian King Cc: Vlastimil Babka Cc: Kirill A. Shutemov Cc: Michal Hocko Cc: Matthew Wilcox Cc: Laurent Dufour Cc: Andrew Morton Signed-off-by: Yang Shi --- Andrew, this should be able to be folded into the original patch. mm/mremap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 3524d16..f9d5d1f 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -566,12 +566,14 @@ static int vma_expandable(struct vm_area_struct *vma, unsigned long delta) * downgrade mmap_sem to read. */ if (old_len >= new_len) { - ret = __do_munmap(mm, addr+new_len, old_len - new_len, + int retval; + retval = __do_munmap(mm, addr+new_len, old_len - new_len, &uf_unmap, true); - if (ret < 0 && old_len != new_len) + if (retval < 0 && old_len != new_len) { + ret = retval; goto out; /* Returning 1 indicates mmap_sem is downgraded to read. */ - else if (ret == 1) + } else if (retval == 1) downgraded = true; ret = addr; goto out;