Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp189437pxf; Wed, 24 Mar 2021 02:40:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNG5y/gfcna0DgCunfsulHpxHgEaESQF7D+GTEdWPxqz5pjn0fuQPnEsXXkK7OAaRNZD6O X-Received: by 2002:aa7:d448:: with SMTP id q8mr2406771edr.345.1616578853757; Wed, 24 Mar 2021 02:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616578853; cv=none; d=google.com; s=arc-20160816; b=QRv1xHz0x/vrc7Umy4RExHXL5r+u+jIjijMC9jVwRPUosC6O+C+ZFBqf+SyweZvlsa opK9bw8R6akiEXGJyeIne5IaGb+1/glhV9QeCpXKpyQfhZJGp9Mw1/vIr6WK4F2dR9tX gzCDKGL1xQTXHjYTVsvgbLrLaLGEHwU8aa+CVSDMaHU8zj2Hy2SvRsO5Lyutqy0zAl1A sN2wRyhQPXhY4Mdx5rlGNfujTcv+ic84jliTYGRbbco2l6fC6xtv+0iMGSF1i1Vur3uh L81anHimDq2P3Unea2vvAZpagG4cLQ5A0L3QaE4AofkMQeQurL2pZz4r5i7aJ/mpyf/O s2MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dmarc-filter:sender:dkim-signature; bh=00TqvYCNeciOSY+tXTmof3mxA8FUNJGcjvkmvoy4PAM=; b=cuHXYJItGv0KlOUokDKr0SImA10fi+Gp9/rBCASodbfnax76smVuqASVlyycPA23Xj mwGNyFSm/7eF/gKIEP1g3d6kLV0HktLrHfB0qNCBDD6yoO+orKJwBptuhhuI9U4yjM/U YGYoifXxmHZ51kibBwFBi98dfKKGQRs9FRndqCFttmuyC5Mrvg0Hd1IbPayYs8CdQkJ1 gf845zbaabfzStyucigPqBA9XA4hqgq/O54bQbVTcHb4/Ys+XyF+dOJKm238qD4NEOcn TWaffp2S+fHAGPCVU1REb+DmMdpGy1JT3qqmureqCjr3DkoJO4oh1V+TAwzyqmyOZsy+ BBpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="kTRu5E5/"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr7si1413757ejc.596.2021.03.24.02.40.31; Wed, 24 Mar 2021 02:40:53 -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=@mg.codeaurora.org header.s=smtp header.b="kTRu5E5/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235055AbhCXDaf (ORCPT + 99 others); Tue, 23 Mar 2021 23:30:35 -0400 Received: from m43-7.mailgun.net ([69.72.43.7]:38235 "EHLO m43-7.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235045AbhCXDaD (ORCPT ); Tue, 23 Mar 2021 23:30:03 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1616556595; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=00TqvYCNeciOSY+tXTmof3mxA8FUNJGcjvkmvoy4PAM=; b=kTRu5E5/jgD43+p5HRdfZTpVyi4sN5QF8e2heWvXmfyCwhO+Ys7CatavgSw3YvWo4Z52e5Xb sYILcvo42iWeIUGRs3VOMPs3xfSMGjlFzi5h2OdMJtKL2oLs3D1VCZiTqkSp8FjZ8PSpel7K HWlNmHuF9hi8YmGnKMvhfdASxuw= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n02.prod.us-east-1.postgun.com with SMTP id 605ab22be3fca7d0a6fc9f8e (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 24 Mar 2021 03:29:47 GMT Sender: vjitta=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id EEBFEC43461; Wed, 24 Mar 2021 03:29:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, NICE_REPLY_A,SPF_FAIL,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from [192.168.0.109] (unknown [103.110.147.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vjitta) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4DE6EC433CA; Wed, 24 Mar 2021 03:29:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4DE6EC433CA Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=vjitta@codeaurora.org Subject: Re: [PATCH] mm: vmalloc: Prevent use after free in _vm_unmap_aliases To: Uladzislau Rezki Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, vinmenon@codeaurora.org References: <1616062105-23263-1-git-send-email-vjitta@codeaurora.org> <20210318165907.GA10448@pc638.lan> From: Vijayanand Jitta Message-ID: <803dc8ec-d1a2-ed26-ddab-a5258e60d318@codeaurora.org> Date: Wed, 24 Mar 2021 08:59:37 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210318165907.GA10448@pc638.lan> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/18/2021 10:29 PM, Uladzislau Rezki wrote: > On Thu, Mar 18, 2021 at 03:38:25PM +0530, vjitta@codeaurora.org wrote: >> From: Vijayanand Jitta >> >> A potential use after free can occur in _vm_unmap_aliases >> where an already freed vmap_area could be accessed, Consider >> the following scenario: >> >> Process 1 Process 2 >> >> __vm_unmap_aliases __vm_unmap_aliases >> purge_fragmented_blocks_allcpus rcu_read_lock() >> rcu_read_lock() >> list_del_rcu(&vb->free_list) >> list_for_each_entry_rcu(vb .. ) >> __purge_vmap_area_lazy >> kmem_cache_free(va) >> va_start = vb->va->va_start > Or maybe we should switch to kfree_rcu() instead of kmem_cache_free()? > > -- > Vlad Rezki > Thanks for suggestion. I see free_vmap_area_lock (spinlock) is taken in __purge_vmap_area_lazy while it loops through list and calls kmem_cache_free on va's. So, looks like we can't replace it with kfree_rcu as it might cause scheduling within atomic context. Thanks, Vijay -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation