Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp133338pxk; Tue, 22 Sep 2020 21:38:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxN8ceSyxLoBLFS/XOMM5WTEZuRlD7FghV6N+FDCwSknJUfg9X6lLlmYsUex3v4280dJTRg X-Received: by 2002:a17:906:375a:: with SMTP id e26mr8148481ejc.552.1600835930934; Tue, 22 Sep 2020 21:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600835930; cv=none; d=google.com; s=arc-20160816; b=Ikojv6qkUzuwIEDkSsSZ/60MNOCTmNDxv030lVG/GvAjoekdnkpDgFn6PM/b3xAb3B pBueMhZ/9/zbsmvQvb5j5VkL6ji0e5iM3u4kA//0GDIgF39TAqD67zIVPG3kUqHsAhLD EWCXEhlSo33poyMMyUkMp67vmWnE5buVoJ5gyD8tNXDibK2DN1np0teccbE6pFDl3Wyl fMvArX/oRgFzX3bZWsbgig1Li9LELH/6bq3XJNN/xdniHwHq8ugBCw1ePqgCpJfE1YGP bp6SyC9AKhkihhb/OaI3sNKIZ/Wzlxs33fsV031Qeyg41xHgH6P+awgHANdcmn029ln2 6B3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FvFGx3rWCRs2m52pGzHi8mNBwRLDuVFOSz8HGbgXm5Y=; b=l1nEyiT3ynS522h8c+TlnXB4TyFIP3MesI5+R2jPdM1b6p7zJ8dXfXajpwtTZQbZnL LXwuNDhpiftWgvXeU2345pS2B4WsI1hcZkcKjkNHg2GLarR8Hmj9i6JolDP357ZWgmm+ hag37tsUnXFQprI8yBmNEUtngq6QUaeSkTY2/TRtliuVOupmjUdqqYrw4GZw31qAzlcx anKt8QLz68RPtU7fnf6ftspcljl+HKRcNBHH+58A2J+UTx9AhXaw+I59LZqdTxRaPFn4 9xtV1Cnf6TPYNJuo6Jr01si4Zm2sxPt53EKI9epWDgJjWDHTrIRDTiPpnUuu3cqeVk9j pZLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Oy3TV/3i"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb10si12042827ejb.590.2020.09.22.21.38.27; Tue, 22 Sep 2020 21:38:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Oy3TV/3i"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726876AbgIWEfI (ORCPT + 99 others); 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; ...