From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8841326AF6 for ; Thu, 16 Jan 2025 09:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737019602; cv=none; b=ropGT8iKT32NFI2XyLXYAo0bo2pkPThkBUYh5f6REp42Gw+cKQcG2bdYrCRMUCk8bI3BbNU/R4j9TYLsQwvqfGlJdWisM4h6dgr2XASbc7akKzRsDJjVZk1bGq0sP0fXnZfjestA1ovZz4Urh/0g5pK2+W4R8F1HtKOLZmOgKhk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737019602; c=relaxed/simple; bh=+JKlRSjyOWCgPAlPWEAArMRh+JnvuFNJEusXtjWjPk8=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:Content-Type; b=SGCNx+1KQj1h4CmspfPS7uxlGaJJJ8tOmW2ch+O7MOQky+QZZzc4taCpc2wKMNOtv5VnpzsJbHorY0sP9Lei7iwzZR04Jdce8K1vEhwD+uadb53R09E781eISIQzBasdmuTOuTOF3lYV1SVaJMqX5toB2q602gf03zj89Vzdzmg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JJ92/VRU; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JJ92/VRU" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2ee46851b5eso1007845a91.1 for ; Thu, 16 Jan 2025 01:26:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737019600; x=1737624400; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:from:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=ZSWQuiysYXgR3ZSI3gPnT5CGQEd98ql8kv5XxPcGvhk=; b=JJ92/VRUib9BYTptd190YJAEHFjiGbpp63jcc90hWEclj8pd+tOj8+Bn99W7X3ASzX 7FVGTBpfy014+Z0gsV0CsOK2WIDu3XzT5rR4eMePZXyzY623jWuqAGjGkmUciOg3NqAL 7i+k24JYG3QcEXidsD2g9qU4mVotgUcugWk3Zoogk4rAZWX8R5B7pNTsRg1SpTeQaFGJ opgo9OQGOeH5EF0hoXdXOjBj3/6MUskoKNNh7yud1jRaYiHMJi1W35NS2iedIl1HhpTk qgsAJwd9s+p5s42mP97VKCcxG7Rv4NgUXp0W5QVpogXSMk/V+Ofmf/3zUzo+L/4JDJZk T6oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737019600; x=1737624400; h=content-transfer-encoding:cc:to:subject:from:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ZSWQuiysYXgR3ZSI3gPnT5CGQEd98ql8kv5XxPcGvhk=; b=N6LWD/gnl9dmaR5zrkLuvlVcD+aywarPqvYBpnxTtF7B3elrTvSv29T1GS8luzjVTh oyeXbCTzEslIFAcwC05wyhmnAC+tksEFgVJwxB+IRmFC+GMNVEyLOJb9A/VpWZ9jn/ni t9fE8QGsotcb8LMQ2aathuROp6RkrmzH2Xy1TBvD1YC7cswbxOX8fyWptWOMtMjgJwNx MWybHIqaJzZOk2m7xleEq77FH/dZxzUqyESky7YIkkF92RFdGFh9vf6rOhQ9K6vVcJ7O d8TxCXbo68bvFv6skSBkfchCvHKTaar+64Nopd/+3H8LcD/UkuJEQbalf9EjhFQsMGog iQHg== X-Gm-Message-State: AOJu0Yxw0ghN+dgtRU6pObxSCuJllGKGkqr1Dl6Wkd50D/4l6eCHkV1u M2nTyrhi7uyOz8Kjt+x7dqZADJgLIMBCLlsReDX18lsYFWWKHqKGGsPlm7kl X-Gm-Gg: ASbGnctPKVl17fZQ9UpdXdn7NJOQ0AdsSzCkrXrsR2l03p0j37nQND8AVBtT3yZbYzE Dsrx5my4rcydeZ1RozVcIll+0HsU04+7eMsBlJSN2DvM/BGXzNSsqGwTlS/h+xYJIAhH2Ya7OQa gjBGUGIZ19LAEWGRsd6OfZ5Ta+YsSSiFS7rWVS0AyQDevr2VvC4XVM8el736RP1z9VEQj0OeGaM 25EZrxh2TwsVSPpSGmJGDStroxW/a48Qu41QDe2f3zodt5q40vvA8ze7Y5Aoz/RKgMkGIvNLnTS /DKOULee96sc4fOyWFo8oUgRwQ== X-Google-Smtp-Source: AGHT+IEj/18p9Y1AvgFYWufECswx5TwJh6c8QEpG1Hu+O3SMWEuW95IXp13Dn5//LNYXxnrEsj0UxQ== X-Received: by 2002:a17:90b:258c:b0:2ee:f687:6ad5 with SMTP id 98e67ed59e1d1-2f548ea5b95mr48234578a91.2.1737019598386; Thu, 16 Jan 2025 01:26:38 -0800 (PST) Received: from ?IPV6:2402:f000:5:2800:f432:8f4d:a17f:4da5? ([2402:f000:5:2800:f432:8f4d:a17f:4da5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f72c214c61sm2831215a91.40.2025.01.16.01.26.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Jan 2025 01:26:37 -0800 (PST) Message-ID: Date: Thu, 16 Jan 2025 17:26:33 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Tuo Li Subject: [BUG] mei: a possible use-after-free caused by concurrency execution To: tomas.winkler@intel.com, arnd@arndb.de, gregkh@linuxfoundation.org Cc: LKML , Jia-Ju Bai Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hello, Our static analysis tool has identified a potential use-after-free caused by concurrency execution in drivers/misc/mei/main.c. Consider the following execution scenario: (The line numbers can be referred to https://elixir.bootlin.com/linux/v6.12/source/drivers/misc/mei/main.c) mei_release() //Line 112 cl = file->private_data; //Line 114 mutex_lock(&dev->device_lock); //Line 123 kfree(cl); //Line 149 file->private_data = NULL; //Line 152 mutex_unlock(&dev->device_lock); //Line 154 mei_read() //Line 169 cl = file->private_data; //Line 172 mutex_lock(&dev->device_lock); //Line 184 cb = mei_cl_read_cb(cl, file); //Line 200 cl_dbg(dev, cl, ...); //Line 275 mutex_unlock(&dev->device_lock); //Line 276 If mei_release() and mei_read() can execute concurrently and the execution order is 114, 172, 123, 149 (free), 152, 154, 184, 200 (use), 275 (use), 276, a possible use-after-free can occur. Our static analysis tool reports this use-after-free when analyzing Linux 6.12. The tool deduces lock() and unlock() pairs with alias analysis. It then applies data flow analysis to detect use-after-free across synchronization points. I am not quite sure whether this possible use-after-free is real and how to fix it if it is real. Any feedback would be appreciated. Thanks! Sincerely, Tuo Li