From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 3FFD4C0044D for ; Sat, 14 Mar 2020 18:21:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D78FF20751 for ; Sat, 14 Mar 2020 18:21:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EluGg2O3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D78FF20751 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1CCB16B0005; Sat, 14 Mar 2020 14:21:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17CA16B0006; Sat, 14 Mar 2020 14:21:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 092CB6B0007; Sat, 14 Mar 2020 14:21:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id E280B6B0005 for ; Sat, 14 Mar 2020 14:21:00 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9CEC3180ACEE9 for ; Sat, 14 Mar 2020 18:21:00 +0000 (UTC) X-FDA: 76594784280.11.walk68_8c65b7d8dc01 X-HE-Tag: walk68_8c65b7d8dc01 X-Filterd-Recvd-Size: 4556 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Sat, 14 Mar 2020 18:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584210059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=C9DfqLtk0vDlWXaqjECLFoszpiCzG9j/FOTAi7CnS+c=; b=EluGg2O37bvRG0E4bUEej1VxUCCutdrGk8dXWMpD3uxidm4i9EWY6ktSSojmLWeUCvoLvd hJNldAbns8axLSd92oGbx35s6jQv7R/UFV9jfnWKNCuvFcmSDgmNo6vXpLjNTcwg3HYYuX woe0rWUBQ2uiKgHKk/r8+TjxKn49xO8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-271-wbA9qoJkNsOr7xpdYyYqLw-1; Sat, 14 Mar 2020 14:20:56 -0400 X-MC-Unique: wbA9qoJkNsOr7xpdYyYqLw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5BE113EA; Sat, 14 Mar 2020 18:20:54 +0000 (UTC) Received: from localhost (ovpn-204-79.brq.redhat.com [10.40.204.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38A5B19C69; Sat, 14 Mar 2020 18:20:53 +0000 (UTC) From: Giuseppe Scrivano To: Mina Almasry Cc: syzbot , Andrew Morton , Linux-MM , open list , Tejun Heo , Mike Kravetz , David Rientjes Subject: Re: [PATCH -next] hugetlb_cgroup: fix illegal access to memory References: <20200313223920.124230-1-almasrymina@google.com> Date: Sat, 14 Mar 2020 19:20:52 +0100 In-Reply-To: (Mina Almasry's message of "Fri, 13 Mar 2020 15:48:36 -0700") Message-ID: <87zhcin6gr.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: Mina Almasry writes: > On Fri, Mar 13, 2020 at 3:39 PM Mina Almasry wrote: >> >> 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 >> >> --- >> mm/hugetlb_cgroup.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> 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; >> } >> -- >> 2.25.1.481.gfbce0eb801-goog Acked-by: Giuseppe Scrivano Thanks, Giuseppe