From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 DC9E93E0C44 for ; Tue, 19 May 2026 08:33:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779179639; cv=none; b=U05gLnRCTUFf4Q3Y3seVxopHR9C2sW+fdqcoHHMGiwy7DTznshsJQCfYHkvqZCKL4IloOVtY501jr66bMiFhEHeg1u0zzDr99m7XIcB0IA6ljfWixx8eb8nKlthDNa+JJq+kfVSnrLCqPQ0pHl40X1ccQ1QCBR0EBA6ZhtIbIMk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779179639; c=relaxed/simple; bh=Yo0EVHV1kiPGFY+ue5QLPkhNG4ekxqZnDLGzfQ6cezk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NBgydmisJNx8RoenBFdPq9Zm7KEl1HuegbLoup20fy4PLzLdxkoJaay62rahT0qEcUYXScXJUn2jwRURE40G2+xoFNhKjlp3YNAakMZw63bH/AR3YfMmp/OyRe45JdtLSIaFDNkmxexEY2rDvAHqtc9y89a7pILTNRAp/J7Lw1Y= 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=EZMdSByH; arc=none smtp.client-ip=209.85.210.50 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="EZMdSByH" Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-7dcc9b506d9so3509500a34.1 for ; Tue, 19 May 2026 01:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779179636; x=1779784436; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=EiakiSkQhw1pZrsQQLBSF74qifypdvMzdt7ZdBqgl/k=; b=EZMdSByHkitVd0FpnpSXiM/NEK0KRAut0elxCZa2XtcIwGoxQh8dKnhGS9hcmb5og3 2jQXRVOMbdlSLn9FSbfTr1+fq1WcP1mBcpnQyj4fam+czVNV55iRLkwUtSIpHKrZHHJ2 B7pxfNjxETMxrd4Ww7jjPEVvIa9W/53S3DWujAE0h+PzVocsf0G9WZzOQorqt/otPTLX 2vVsXwPtJFM3Ada3yN3DwmhvZPPsFhV4ouE9Fd4t/GsCuHMYauYSvwRGvyvauZkZOtKs U4IVmjRTyPZbQtuomjlprbpIcwgEzyFo5viEalL2M0+gcmySr2Z6bIU7L8fYtuuRncQ3 DHEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779179636; x=1779784436; h=in-reply-to:content-transfer-encoding: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=EiakiSkQhw1pZrsQQLBSF74qifypdvMzdt7ZdBqgl/k=; b=D8Kb8RiNPRawIqmdWzD1snRF+XC3pMjkVrIlhZhS6xUUvRYBkwFs6ZDniG620Eo3Kx +qqU46VhySxld3sCTkB5gi1PKbMFM2AOtQ34QGIHzKzpCVxkx84nZ7uBIYiW4kXlAfxQ 8VQcz6JylZUFH+c08gomAok0PHZnmV/ISemeDaVjfGUoTgkRIENQFKrU2THmRNMD+iVh PSJQJ37Bb4Iy5jaSATarX1iY+JDXSCDaWu9DlkMxrOjjItlNZlEMJ4W5u/0nxkFZhfKx igTfk9fZp9RupxIiITFP1SsStFOvSQz98MLPe0E3V2mw9lyZiGE9hm6SLSlndQE6ShiR cEpQ== X-Forwarded-Encrypted: i=1; AFNElJ+Fv8fZiYT8XEcZecZZzdEf6L4EV6w04CN5oaYO21WudFwH5J9tyJggKpQ37a0PiCb2SqGXu9u++76s5qc=@vger.kernel.org X-Gm-Message-State: AOJu0YwK2kFklL+DqPhds7PlOoWxwOPY45xcQitAOWBlJu7JhDI3ukqy PTpvk/8qd0klGmYz/s/eaeVilL+BiF2uU9Hckr8wUm5HIaDJYqukYPQW X-Gm-Gg: Acq92OH/d+oG8reJOf2nkqSX6VycNatJeVZi/OrKYkg1UElHiC/X1KHE7r+FS6JrTvH gFaHEVX445e9PnnDMTPuvyoj6DhfbAKKlvSv7K3kb6Ybb64RN68u8fL02fc9pgd7nPJqVrmD6xB wqhQZv7jh2AwXOhXORpXeyQmlgwR5qoyYydck0XOnAcofM/oR3h9RQ4qUhNJkfBCw5ROl2NhNS+ hJvBcrs4l2fuMuFGAJvc7+VLmtw7Di4+dgD9PE1pzsYazREuBDiLDiX/BaVz2HMyrlrZrqtcsaW oPwHvmm5jR1NIxrEFggnvnwkxT1rT3tn4gZUVY1iU94cfXqCtfzmOwi2nKnaJ0xIpKpr1pIkF71 RcfV4wN8zIM5FD9Q3jLxJkwlJLd0dWQ0HNS3zr1y1tihsQqOpRaU/mSOFnGd2pQO/Q9r5rkYqu0 6LLltqLLP5xbTMCKQYR7qVc9m8HFiEY95E+qKo3q6eqGmDWOFBv2r5Wp4jUrlVsaAfaAaEsTCu1 TMExb8dB9+ZqCP1wysK X-Received: by 2002:a05:6830:3812:b0:7e4:230:96ca with SMTP id 46e09a7af769-7e4fa05a5bfmr14260526a34.21.1779179635795; Tue, 19 May 2026 01:33:55 -0700 (PDT) Received: from fedora ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e55b7c68d6sm9344663a34.3.2026.05.19.01.33.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 01:33:55 -0700 (PDT) Date: Tue, 19 May 2026 16:33:49 +0800 From: Ming Lei To: Hongling Zeng Cc: Hongling Zeng , axboe@kernel.dk, ming.lei@canonical.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] block/loop: Fix NULL pointer dereference in lo_rw_aio() Message-ID: References: <20260519040103.22776-1-zenghongling@kylinos.cn> <6A0BFDE2.5000808@126.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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6A0BFDE2.5000808@126.com> On Tue, May 19, 2026 at 02:06:26PM +0800, Hongling Zeng wrote: > Hi, > > Thank you for the review. > > 在 2026年05月19日 12:42, Ming Lei 写道: > > On Tue, May 19, 2026 at 12:01:03PM +0800, Hongling Zeng wrote: > > > lo->lo_backing_file can be NULL when the loop device is being cleared, > > > causing NULL pointer dereference in lo_rw_aio(). Add a defensive check > > > to prevent kernel crash. > > > > > > In v7.1-rc tree, lo->lo_backing_file is cleared in __loop_clr_fd(), which > > > is called from lo_release() only, when it is guaranteed that there isn't > > > inflight IO. > > > > > > So care to share your stack trace? > Syzkaller has managed to trigger NULL pointer dereference in lo_rw_aio(). > Tetsuo Handa encountered the same issue (commit 1a83d226268cf), but his > patch only adds diagnostic logging and is marked "not for upstream". > > > Also fix loop_attr_backing_file_show() to use PTR_ERR_OR_ZERO() > > > for correct NULL pointer handling. > > > > > > Fixes: bc07c10a3603a ("block: loop: support DIO & AIO") > > Can you explain how the issue is introduced in above commit? > The issue was introduced when lo_rw_aio() was added in that commit, > which dereferences lo->lo_backing_file without NULL checks. While the > design assumes no inflight IO during __loop_clr_fd(), fuzzers have > found edge cases where this assumption doesn't hold. What are the edge cases? > > > > Signed-off-by: Hongling Zeng > > > --- > > > drivers/block/loop.c | 5 ++++- > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > > > index 0000913f7efc..d8db1b0d8018 100644 > > > --- a/drivers/block/loop.c > > > +++ b/drivers/block/loop.c > > > @@ -397,6 +397,9 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, > > > cmd->iocb.ki_flags = 0; > > > } > > > + if (!file) > > > + return -EIO; > > If lo->lo_backing_file may become NULL, it isn't enough to add check here > > only, cause it can be observed in lo_req_flush() & lo_fallocate() too. > > > > > > Thanks, > > Ming > You're absolutely right. Tetsuo's approach only adds logging to help > diagnose the issue (and he marked it "not for upstream"), but it doesn't > prevent the crash. > > To properly fix this, I need to add NULL checks to all functions that > dereference lo->lo_backing_file: > - lo_rw_aio() > - lo_req_flush() > - lo_fallocate() > - loop_update_limits() > - lo_can_use_dio() > > What's your preferred approach? > 1. Simple NULL checks in all functions > 2. A helper function with proper locking > 3. Your recommendation > > Let me know which approach you think is best, and I'll update the patch > accordingly. It isn't supposed to happen, so please root-cause first before sending any workaround. Thanks, Ming