From patchwork Tue Apr 9 19:56:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Augustin X-Patchwork-Id: 1921616 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VDcCx4tQcz1yYM for ; Wed, 10 Apr 2024 05:56:28 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ruHZo-0003GO-Ga; Tue, 09 Apr 2024 19:56:16 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ruHZj-0003GF-Vh for kernel-team@lists.ubuntu.com; Tue, 09 Apr 2024 19:56:12 +0000 Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 9D4A940039 for ; Tue, 9 Apr 2024 19:56:11 +0000 (UTC) Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-6180225775bso37216227b3.2 for ; Tue, 09 Apr 2024 12:56:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712692570; x=1713297370; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3c+yL/HLDYOeIvj5wVRuad1W/RPRQYGLyPSa9f8vkkY=; b=YmxvRZPgEe+LtP1dolpvWa4OqV1aTF2A8FkIu/MSJJBvLrMBLylYC0Yswyq6fIM0tM cL5D0YHJXU3kRS9skoMBaFPGJreh0nsGQOoM2QsZbbi16wj24ReeflxvGOd548MNzZwk H3BgvkCZu/doOaG9Ne7Mjv06Tv4nBtTjKC6HjdpaoGhS1dVbFTS0z/6U2I6f53LqSJFp sn0n8aP4SSoD4IHYX3LirZlnOCbC1w4DG68Ie7QldvEQK2E6Zmxgg1eU9aJpBWRJBFhE ZEM+K1GcQ/ApU3r7ewG4lp2oCP2tmxVp0UHrPes3kicbYS27/yTxM7+jSHsSCmbB7kao U/bA== X-Gm-Message-State: AOJu0YyhXPRAVP6d4Z52S0acz+Tx9Hqw0xK1zYHUys1iJvOUgd8/yf8d lEopOspNASjnWK6BS07vQYX5/97g6qgG4ok6dSP3fsu3L3beJmt1gli2IYEmM2Vy30FqAvETyPz OnmV8iDiCb8C2pB/TWz/ENb6GZayBGVfB1SBl/S358H5nn9wI/XbN+5GgPP9yG4phwCHzntqltJ OqRkJa2Zkq+A== X-Received: by 2002:a81:6088:0:b0:610:b464:9f1a with SMTP id u130-20020a816088000000b00610b4649f1amr651162ywb.45.1712692569990; Tue, 09 Apr 2024 12:56:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwS4fr1CkiNi55H6VMDjUayR4iqFgBNOQOQ0DFr8dQZK329RCGatL3K5hZieavV3bFbPR6pg== X-Received: by 2002:a81:6088:0:b0:610:b464:9f1a with SMTP id u130-20020a816088000000b00610b4649f1amr651149ywb.45.1712692569565; Tue, 09 Apr 2024 12:56:09 -0700 (PDT) Received: from localhost ([216.114.108.10]) by smtp.gmail.com with ESMTPSA id m4-20020a819e04000000b00618169e9828sm903075ywj.14.2024.04.09.12.56.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 12:56:09 -0700 (PDT) From: mitchell.augustin@canonical.com To: kernel-team@lists.ubuntu.com Subject: [PATCH] aio: Fix null ptr deref in aio_complete() wakeup Date: Tue, 9 Apr 2024 14:56:07 -0500 Message-Id: <20240409195607.759234-1-mitchell.augustin@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Kent Overstreet BugLink: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2058557 list_del_init_careful() needs to be the last access to the wait queue entry - it effectively unlocks access. Previously, finish_wait() would see the empty list head and skip taking the lock, and then we'd return - but the completion path would still attempt to do the wakeup after the task_struct pointer had been overwritten. Fixes: 71eb6b6b0ba9 ("fs/aio: obey min_nr when doing wakeups") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/linux-fsdevel/CAHTA-ubfwwB51A5Wg5M6H_rPEQK9pNf8FkAGH=vr=FEkyRrtqw@mail.gmail.com/ Signed-off-by: Kent Overstreet Link: https://lore.kernel.org/stable/20240331215212.522544-1-kent.overstreet%40linux.dev Link: https://lore.kernel.org/r/20240331215212.522544-1-kent.overstreet@linux.dev Signed-off-by: Christian Brauner (cherry picked from commit caeb4b0a11b3393e43f7fa8e0a5a18462acc66bd) Signed-off-by: Mitchell Augustin --- fs/aio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/aio.c b/fs/aio.c index 9cdaa2faa536..0f4f531c9780 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1202,8 +1202,8 @@ static void aio_complete(struct aio_kiocb *iocb) spin_lock_irqsave(&ctx->wait.lock, flags); list_for_each_entry_safe(curr, next, &ctx->wait.head, w.entry) if (avail >= curr->min_nr) { - list_del_init_careful(&curr->w.entry); wake_up_process(curr->w.private); + list_del_init_careful(&curr->w.entry); } spin_unlock_irqrestore(&ctx->wait.lock, flags); }