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 58465C4363D for ; Wed, 23 Sep 2020 04:35:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E79FD214F1 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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726883AbgIWEfI (ORCPT ); Wed, 23 Sep 2020 00:35:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27231 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgIWEfI (ORCPT ); Wed, 23 Sep 2020 00:35:08 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; ...