From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 D06EF388377 for ; Tue, 5 May 2026 03:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777951515; cv=none; b=h689W1dYrIce8y8sRnVh4KxEmqwhikyI7kn9/M0VGRi/O+HI+w1t+IrT8Ceo9CNJIAWeDFNfn16okNx+TP7qE0UeyCOnP3TjHCiaNEFv0MgpYs+BOr79OZNqvnKeK+2mY7d3N3l1/257DEU6eaHk9o3uO0gFMDP3RytBaN+irDs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777951515; c=relaxed/simple; bh=R5q6IqVd1ysQsurgFaqaoDH3f/2x1lsyKg2rGu8qncc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m60hQbOj6zZuCf4yrNPugsuieZJS7qdcz0+OPK9kdAc5yT9DtcDjw0g3VpqeSLtF9TsKMYA8ykr808MXFdGohPNW9/vpCtY9nEZGJLcsKhYWeJVpammlNNTAYTsA/mBDmkEeCNbeaiUOK3LmUbEF+mKuC1YeA3KG8YUx5h/CywI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=aT5Xz6/Q; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aT5Xz6/Q" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-c6dd5b01e14so1571992a12.0 for ; Mon, 04 May 2026 20:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1777951513; x=1778556313; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=IOgn1ypZ4nduY+SbHUWa7G7iPPnNvuWv4v36Xev0RXs=; b=aT5Xz6/QaXa7SsUxXo/X7867gHIU7vHTL1syWa9RI7hxrZeYrp1OP+Nyve/JQOVkRy GL/4HI3RacfE7CJ/PEfpDexLkVHm0I1FwKU6kAUp4mWnjfGYl7TB9hsZTeLxcaZ5M8SD g92n6nJtdUh78TTyIds1sBizpn7sM87O3f0LI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777951513; x=1778556313; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IOgn1ypZ4nduY+SbHUWa7G7iPPnNvuWv4v36Xev0RXs=; b=BZCpBmpWvykNBKofQSg1SQ8fmTQYw5f8VL8KqyYHAz29KnwutyIs0ybjrOLvcWpihv fc6IE6dS2RTi8vDpfL9WSvUYo0w0o4/QAaUspm+Sb8Pwe2rwl09kz0n4lPpVzmTMI5QO dW+jWp1sSBeadqwgDIoPftRaM2uaPLhnRXy0iltEEsMHSMcGRhAjOqWof1+f8aO8ZHRX 6Bx5ld122Pr31x5CMAB1RcOmUSLBF+WYYOl3/BWeeBmD3rxua9EGUI18I614xSGNnktT Bki4l3cYIB86iUPcgcHuzYkjYGhoEUklENtrjzY7oBG6VtWC5igpjXsX9NowL2E15yoq oh9g== X-Forwarded-Encrypted: i=1; AFNElJ8nzN59FtXHdmHv8woU7FX8NV9Wwsdsi2qpuCVABD30ydh9al131bfik+uXz2iCxI16v1mYpYMINbUSl20=@vger.kernel.org X-Gm-Message-State: AOJu0YwTWBLhNUbcvpj9viH6kiSYrvJqbKZ2hfaCio24w85ZVDrk43fe Yr+aMu15GGt742vNvKSV3ldQWcERcSRLRF86kRX/5mys7E8BvEyqTgY8y35IwBzP5g== X-Gm-Gg: AeBDieswlRNXaRxppmWzAfpvCE049lEaxsR3gy3xqC1+Y/dY/E+JjBZUNAJenwpYNN6 2nKg7SpRQzT+609dBw/7g1QzGYDVF224MjqmYA6RxlTiy43pC7pbd82oNOq7LbArkAISqEko4zN pR1EuLCqLOPsCJiwy5Uk9ZXR8fS3Jz2kx/JMhn8g44eyxQUlG1DpGbNf8Ph7dXo9XCw+GhnFs85 GJJgecH50JPcIoTDoUFcV1jUArX2GYWvuJ59IQ82FrT6ZSyLjIHGYcZHdDJ42fzTHdgfshj6pxL Gr5OJFDaX0DpZRLZeGKQrj3RRVUay90lWAfYJR43DVm4oUrsd6KPkOsHdM7UHM6iUBE+Qoe5zNL AeB+wM5w6hidHT8gFx2NZMPuMffTAAhmOdwSlpxmGwLPPrFlH3Etieo/xzQtXtcxC4jhOsoX14F ej2pSjEPKN40DY0hzkw5Arr1TbE6D0QOwM/6EOyP/KKo1dkb0QK2nPkOY/G4gZo4rad2NJcYjzU HBIMCZZY6vJ X-Received: by 2002:a17:903:3c66:b0:2b2:4cd2:e16c with SMTP id d9443c01a7336-2b9f260d87bmr118255855ad.20.1777951513193; Mon, 04 May 2026 20:25:13 -0700 (PDT) Received: from google.com ([2a00:79e0:2031:6:1159:b1b3:930d:d5eb]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b9cae0e605sm119301085ad.41.2026.05.04.20.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 20:25:12 -0700 (PDT) Date: Tue, 5 May 2026 12:25:07 +0900 From: Sergey Senozhatsky To: Andrew Morton , Richard Chang Cc: Minchan Kim , Sergey Senozhatsky , Jens Axboe , bgeffon@google.com, liumartin@google.com, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] zram: fix use-after-free in zram_writeback_endio Message-ID: References: <20260504123230.3833765-1-richardycc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260504123230.3833765-1-richardycc@google.com> On (26/05/04 12:32), Richard Chang wrote: > A crash was observed in zram_writeback_endio due to a NULL pointer > dereference in wake_up. The root cause is a race condition between the > bio completion handler (zram_writeback_endio) and the writeback task. > > In zram_writeback_endio, wake_up() is called on &wb_ctl->done_wait after > releasing wb_ctl->done_lock. This creates a race window where the > writeback task can see num_inflight become 0, return, and free wb_ctl > before zram_writeback_endio calls wake_up(). > > CPU 0 (zram_writeback_endio) CPU 1 (zram_complete_done_reqs) > ============================ ============================ > spin_lock(&wb_ctl->done_lock); > list_add(&req->entry, &wb_ctl->done_reqs); > spin_unlock(&wb_ctl->done_lock); > while (&wb_ctl->num_inflight) > 0) > spin_lock(&wb_ctl->done_lock); > list_del(&req->entry); > spin_unlock(&wb_ctl->done_lock); > // num_inflight becomes 0 > atomic_dec(&wb_ctl->num_inflight); > returns to writeback_store(); > // frees wb_ctl > release_wb_ctl(wb_ctl); > > // UAF crash! > wake_up(&wb_ctl->done_wait); > > Fix this by moving wake_up() inside the done_lock critical section. > This ensures that zram_complete_done_reqs cannot consume the request > and decrement num_inflight until zram_writeback_endio has finished > calling wake_up() and released the lock. > > Fixes: f405066a1f0d ("zram: introduce writeback bio batching") > Signed-off-by: Richard Chang Acked-by: Sergey Senozhatsky