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=-5.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 99B17C2D0A8 for ; Wed, 23 Sep 2020 04:35:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1092F21941 for ; Wed, 23 Sep 2020 04:35:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Oy3TV/3i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1092F21941 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 F33BE6B0003; Wed, 23 Sep 2020 00:35:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBC366B0055; Wed, 23 Sep 2020 00:35:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D838C6B005A; Wed, 23 Sep 2020 00:35:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id B89B46B0003 for ; Wed, 23 Sep 2020 00:35:08 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6E3DC181AEF00 for ; Wed, 23 Sep 2020 04:35:08 +0000 (UTC) X-FDA: 77293061496.20.heart32_3f1315027153 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 4BBE1180C07A3 for ; Wed, 23 Sep 2020 04:35:08 +0000 (UTC) X-HE-Tag: heart32_3f1315027153 X-Filterd-Recvd-Size: 3381 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Sep 2020 04:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600835707; 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=FvFGx3rWCRs2m52pGzHi8mNBwRLDuVFOSz8HGbgXm5Y=; b=Oy3TV/3iNFGOuUspRM6EvsrWfeWCPqN1Wd0HwF/lHJabWGeWU/EVlzKJb3trAa7iqmumhB FzIyMhgVKr9NtKnvIAPjaLgW2HcnRZpCp44tIO3te7YE8fqVYBCjxRbSgMqBtkqeVCQMyr 4ZNT3PRXCvxMYhF6LWlI5Qw+sTkSsU0= 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-590-THBCtSVMNrKph0Y5ketjig-1; Wed, 23 Sep 2020 00:35:04 -0400 X-MC-Unique: THBCtSVMNrKph0Y5ketjig-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82DB41007468; Wed, 23 Sep 2020 04:35:03 +0000 (UTC) Received: from optiplex-lnx (unknown [10.3.128.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 779D010027A5; Wed, 23 Sep 2020 04:35:02 +0000 (UTC) Date: Wed, 23 Sep 2020 00:34:59 -0400 From: Rafael Aquini To: "Huang, Ying" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org Subject: Re: [PATCH] mm: swapfile: avoid split_swap_cluster() NULL pointer dereference Message-ID: <20200923043459.GL795820@optiplex-lnx> References: <20200922184838.978540-1-aquini@redhat.com> <878sd1qllb.fsf@yhuang-dev.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878sd1qllb.fsf@yhuang-dev.intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: On Wed, Sep 23, 2020 at 10:21:36AM +0800, Huang, Ying wrote: > Hi, Rafael, > > Rafael Aquini writes: > > > The swap area descriptor only gets struct swap_cluster_info *cluster_info > > allocated if the swapfile is backed by non-rotational storage. > > When the swap area is laid on top of ordinary disk spindles, lock_cluster() > > will naturally return NULL. > > Thanks for reporting. But the bug looks strange. Because in a system > with only HDD swap devices, during THP swap out, the swap cluster > shouldn't be allocated, as in > > shrink_page_list() > add_to_swap() > get_swap_page() > get_swap_pages() > swap_alloc_cluster() > The underlying problem is that swap_info_struct.cluster_info is always NULL on the rotational storage case. So, it's very easy to follow that constructions like this one, in split_swap_cluster ... ci = lock_cluster(si, offset); cluster_clear_huge(ci); ... will go for a NULL pointer dereference, in that case, given that lock_cluster reads: ... struct swap_cluster_info *ci; ci = si->cluster_info; if (ci) { ci += offset / SWAPFILE_CLUSTER; spin_lock(&ci->lock); } return ci; ...