From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B84ED396562 for ; Mon, 10 Aug 2026 09:46:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786355202; cv=none; b=j0zNWDSE55n5pcBlJLxG1wboqWwZytLVOdnQLabG+w8lpw9PYIN32qTAhPmRGpeAMYESgjQYjLkkWfZ0q+I+lN76v+3Ju/lZtCb1CB6OomW7YUqzaNSuLwQepFqzI2UL3aik8BJF941g7eSSywCW0I33J72fmZ7kK/kwXwHeB1g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786355202; c=relaxed/simple; bh=GFClniVWqeMAfO1ThfUgSAgH7y/ZsSnk5hpoki5yf3o=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=uSB6SPclgCE7xRp3jfHDLRTWtlax5uFFGH07TPcF33xMtsszSBReOssQtmzNT0+m41T65c8gPgQ7uLKdsjApKYDThkFMff+8slTux9LgjK5g4vJ+OLXpKKUi40updWJxZNMpJFFXme0H4p8i0gAuq/AT8p+cLKP7XVGDkTIyH60= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gwYHTDoR; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gwYHTDoR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786355199; 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=qux7+j8dXaPrVpMJRdGYi24EXrfglNjwCN8pMONiLkM=; b=gwYHTDoRNmdUtpOqK9c+cKjvDbsiVyR0qOXbBKpPekgBAE3ixkMXB4s8uxzC5VbutZb3Hs ZWYGXA7TfrienwaSNxAR9T/kfZiA4+49y27mlsAm06mEImDUp7gDe6TH+LXFqggoOlD4nP /K3IQ8qsRCY5HrV0m/1fR1gI96YCDrs= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-1aCVgvigNlKExymPORSiXQ-1; Mon, 10 Aug 2026 05:46:38 -0400 X-MC-Unique: 1aCVgvigNlKExymPORSiXQ-1 X-Mimecast-MFC-AGG-ID: 1aCVgvigNlKExymPORSiXQ_1786355197 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 191D91955F5A; Mon, 10 Aug 2026 09:46:37 +0000 (UTC) Received: from [10.44.32.79] (unknown [10.44.32.79]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 12E39422; Mon, 10 Aug 2026 09:46:34 +0000 (UTC) Date: Mon, 10 Aug 2026 11:46:29 +0200 (CEST) From: Mikulas Patocka To: Runyu Xiao cc: agk@redhat.com, snitzer@kernel.org, dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org, jianhao.xu@seu.edu.cn Subject: Re: [PATCH] dm-crypt: unlock allocation mutex before retry In-Reply-To: <20260809051839.3504080-1-runyu.xiao@seu.edu.cn> Message-ID: <36ae1bb3-09ad-77a2-15fb-4fa76208ad0c@redhat.com> References: <20260809051839.3504080-1-runyu.xiao@seu.edu.cn> 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 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 On Sun, 9 Aug 2026, Runyu Xiao wrote: > If the initial GFP_NOWAIT page allocation fails, crypt_alloc_buffer() > sets __GFP_DIRECT_RECLAIM and retries while holding bio_alloc_lock. If a > later page allocation fails, the retry edge bypasses the common unlock and > reacquires the same mutex. This can deadlock the dm-crypt I/O path and > leave I/O for the affected mapping stalled. Hi When __GFP_DIRECT_RECLAIM is set, mempool_alloc can't return NULL. So, the bug can't happen. Mikulas > Release the mutex before retrying, but only when this attempt took the > direct-reclaim path; the first attempt did not acquire it. > > This issue was identified by a static-analysis checker and manually > confirmed by following the retry control flow in v6.1.66 and current > mainline. A source-level control-flow check verified the vulnerable > ordering and the unlock-before-retry ordering after this change. A small > POSIX-thread model checked only the mutex re-acquisition condition; it does > not exercise dm-crypt. > > Fixes: 7145c241a1bf ("dm crypt: avoid deadlock in mempools") > Cc: stable@vger.kernel.org > Signed-off-by: Runyu Xiao > --- > drivers/md/dm-crypt.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c > index 608b617fb817..aabb9a5f85a7 100644 > --- a/drivers/md/dm-crypt.c > +++ b/drivers/md/dm-crypt.c > @@ -1674,6 +1674,8 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned int size) > if (!pages) { > crypt_free_buffer_pages(cc, clone); > bio_put(clone); > + if (unlikely(gfp_mask & __GFP_DIRECT_RECLAIM)) > + mutex_unlock(&cc->bio_alloc_lock); > gfp_mask |= __GFP_DIRECT_RECLAIM; > order = 0; > goto retry; > -- > 2.34.1 >