From patchwork Fri Mar 13 22:39:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 11437963 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97B13913 for ; Fri, 13 Mar 2020 22:39:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 627142074F for ; Fri, 13 Mar 2020 22:39:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="O3DKp8Qs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 627142074F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 715BC6B0003; Fri, 13 Mar 2020 18:39:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6C6866B0006; Fri, 13 Mar 2020 18:39:34 -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 5DB926B0007; Fri, 13 Mar 2020 18:39:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id 455706B0003 for ; Fri, 13 Mar 2020 18:39:34 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EDCEF181AEF1A for ; Fri, 13 Mar 2020 22:39:33 +0000 (UTC) X-FDA: 76591807026.18.war94_1947a91237751 X-Spam-Summary: 2,0,0,76dbb0d8ad190481,d41d8cd98f00b204,3patsxgskcgudopdvubplqdjrrjoh.frpolqxa-ppnydfn.ruj@flex--almasrymina.bounces.google.com,,RULES_HIT:41:152:355:379:387:541:800:960:973:988:989:1260:1277:1313:1314:1345:1431:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3352:3865:3866:3867:3870:3871:3872:3874:4470:4605:5007:6261:6653:9969:10004:10400:11026:11658:11914:12043:12296:12297:12438:12555:12679:12895:13069:13221:13229:13311:13357:13846:14093:14096:14097:14181:14394:14659:14721:21063:21092:21444:21451:21627:30054:30064:30070,0,RBL:209.85.216.74:@flex--almasrymina.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: war94_1947a91237751 X-Filterd-Recvd-Size: 4295 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Mar 2020 22:39:33 +0000 (UTC) Received: by mail-pj1-f74.google.com with SMTP id p3so6436388pjo.4 for ; Fri, 13 Mar 2020 15:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:cc; bh=k5Th5oxzja32CITvsP8bvPqYgNLWg942G74ndA2m4k0=; b=O3DKp8Qsv519WV/tqDln4JX2s0hw+20b1URD4K35HEuGs+5LAqimZb8UaFqOn6MhrR mSe9frZxpsvauQVmA+31s/3/ak+V2LLBs1B6zotCjy98VWLOhWRL8Mgl7VQhtWQ0Z958 fyryzDnSDeKmUeElekMPjtz0Y0kg5/OX1TMd50ysdUYN6FRlgRAJ1IrFEp5iAsWrlAxs 7g1/cjr5CmPf1zFwiBBTB2fnZALddvE1y/+4uVoAxYDsF2ajqvlArLg3XLyA/qek0mrX 6Ix3yoCFAsD0l60WoBi8Ot4COCkewGtLUZxJR98mzyL3OahAG3BTQuOplFSr4jLKk0ha yO1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:cc; bh=k5Th5oxzja32CITvsP8bvPqYgNLWg942G74ndA2m4k0=; b=aj0FQ5O2n+9ZT8m8vR93UKAQcTKtWa+kku/LtuRDe4+2n9J856LMMLhVaMMUJiJNnf T/RC6oGqV2DsUNhjptVQ7Q6oYsXWf4FiXJtC1BiKqhb+tHxwdSJAN6VVIlbD/ftMM+a6 naBzZ9WzGNj89w56aw3hsIAnHaI7ccXvLT/YEfuCbrPeE2TJ2ikUohNB4EDuYe4ZQ3Y3 Y6XhdnpSWKSP+aPocIey8f4Jz6xcQBo6EsSLoQoWPPPe+rIb2lYkfCUeVs4TX7uNPHxv XkQwlX6xTWibOO8/pCg9JE8fJ5/ZLJ0HAqhC6yFMXGDz/u/1hdjCAjhPY+6lK6Ik///W BAnA== X-Gm-Message-State: ANhLgQ2s5yYywRr/5yAzflF5ejxJpdeBsEHqf/DOWtzpC8kuKWYrRiOn YFuHUj6ygbtEsO58k5J0yKYi1F9Pe9W5uh+/3A== X-Google-Smtp-Source: ADFU+vvI64pl/GDQ5FTOUMsfshjKMu6JoRvfa2sz4J7N5BTtHp+LsnvTNnevAHQLtfPe+LqgUhtwMSeKQMWYJqKPqw== X-Received: by 2002:a17:90b:1b01:: with SMTP id nu1mr5402015pjb.129.1584139172402; Fri, 13 Mar 2020 15:39:32 -0700 (PDT) Date: Fri, 13 Mar 2020 15:39:20 -0700 Message-Id: <20200313223920.124230-1-almasrymina@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog Subject: [PATCH -next] hugetlb_cgroup: fix illegal access to memory From: Mina Almasry Cc: Mina Almasry , syzbot+cac0c4e204952cf449b1@syzkaller.appspotmail.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Giuseppe Scrivano , Tejun Heo , mike.kravetz@oracle.com, rientjes@google.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: This appears to be a mistake in commit faced7e0806cf ("mm: hugetlb controller for cgroups v2"). Essentially that commit does a hugetlb_cgroup_from_counter assuming that page_counter_try_charge has initialized counter, but if page_counter_try_charge has failed then it seems it does not initialize counter, so hugetlb_cgroup_from_counter(counter) ends up pointing to random memory, causing kasan to complain. Solution, simply use h_cg, instead of hugetlb_cgroup_from_counter(counter), since that is a reference to the hugetlb_cgroup anyway. After this change kasan ceases to complain. Signed-off-by: Mina Almasry Reported-by: syzbot+cac0c4e204952cf449b1@syzkaller.appspotmail.com Fixes: commit faced7e0806cf ("mm: hugetlb controller for cgroups v2") Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Cc: Giuseppe Scrivano Cc: Tejun Heo Cc: mike.kravetz@oracle.com Cc: rientjes@google.com Acked-by: Giuseppe Scrivano Acked-by: Tejun Heo --- mm/hugetlb_cgroup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.25.1.481.gfbce0eb801-goog diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 7994eb8a2a0b4..aabf65d4d91ba 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -259,8 +259,7 @@ static int __hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, __hugetlb_cgroup_counter_from_cgroup(h_cg, idx, rsvd), nr_pages, &counter)) { ret = -ENOMEM; - hugetlb_event(hugetlb_cgroup_from_counter(counter, idx), idx, - HUGETLB_MAX); + hugetlb_event(h_cg, idx, HUGETLB_MAX); css_put(&h_cg->css); goto done; }