From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 930C51A9F82 for ; Sun, 31 May 2026 12:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780231963; cv=none; b=bpiqzuQoKej953ZfIsBED5mpVIRRKeiQuMxF5JrBMWfrOysoxgnI+0J8dQtu2d4TNz+kWVmfwNFvEdEgLrrGrUN+yr/ofmyiNVyqxJrJ62CULOoLTpUyj6ITRUohX8iXE+6F7cKtpQTv4Md5oKA/N4yetarFaa2vAOY07OSx90U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780231963; c=relaxed/simple; bh=x8mfz075moeph0upF3Mu3jpczbDMMZHuc5hRryJ6wyg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=a7X7HGN64nRqyeturhGEr7JUf5EQ7UERpLOtO+LCs1h15Ebd7bL4RlEuCS/PpoxKH9wMkcxhOoFTHZlumiAxfI3wPbbzMGjadEFt2ux7v0J1Q5NgTtqNgQ0d7QsuVWXA7xg91565tWd/6XoUU2KL4N4XVtHaUd1RSqEKfltYO6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=kdwcAk+q; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="kdwcAk+q" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-91550eced6bso69758585a.1 for ; Sun, 31 May 2026 05:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780231961; x=1780836761; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OnMQ970O/37FDrK1Y36am7zIeSijQMUukVCUSJ3uyGk=; b=kdwcAk+qz5dYZlqVRUIFLZ5UdtfYxRTViVjSm10SH2lvAOTY9UIQARP0v18awLcFAY k5rwJmsmSiMjzXQasuXWI+M7ZLQb3ZYj3bgYUxCGp7fQt9Gwh+gdoqx4Y1mlunz7VTbv KoNPjubkzp17E6sPUpebCW26UoVLJryYO4P/8/kxkMjuVqTQ2CHUq8deZPqD+FZgqMha +diyv4ON4kngzjUtOxb35xR8WkLn3LHmnfZYITRSZqCD8zn462jWOJTtmO7YQ4CAwIzo OyF9E4o83pSbK7cu4mNFuuoD8NirlUC6kwi/xfHziTXKJsoactY3Uir6wh4sGsovG3sz 76BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780231961; x=1780836761; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=OnMQ970O/37FDrK1Y36am7zIeSijQMUukVCUSJ3uyGk=; b=Q4k2jFZrMZUFJ6rpq9bQ7rA4iGNdOJ7eCOS/q4/OtiVnWYBOHXp/JKDunsbU2I/NMI kSaKc9G7v0F3M1MhID4LfdqdELjtvBGPG8i7iqIno8bf9SYYU/25PWat10iEkm5P6NGn JHq+AA5V+T1ijwNn9nLqY6ggQj/zqXY/zP3y4x1tTjiGd8E5ENSvbpX4o46OlbtHMmqy XFoqsj16QTL4hIissGGPktt/JVYByDXxnNJFLc/LgAPaNl8y4++UPG1P3WGhIqWi1lcV WeaTTHNmtSZRhsZgPPwBwSTj4zvGxYaIShlm9+OafDGEp+Sl7EecWoAGsKUKOdU+zy5Y V/ig== X-Forwarded-Encrypted: i=1; AFNElJ8LNjL8h0Y5XBTt4ov42zRP51aQ2Sjpcz/ULjvC2RVVqusMslDeSxO5xly++rE6E2Xeqbt3B7v2xnVoxHk=@vger.kernel.org X-Gm-Message-State: AOJu0YztoqP4S7tHOkbcvvuqTvcO5N5y4J3425S+hEX5fwCXdsvcKvaE UrkesQN+4bEjvUo1i8xZX6/eWLJeriR9aLjZ0nwdBFyPxieyLfh7/W7ZILquXFMKd/c= X-Gm-Gg: Acq92OE4+gKriauTmkSEbp2xGsiHs+PFohvu5T9WuFQfHj9voE6oRtgXml00aHgX5EI NIcSQvLgEPfYDJauQHDKdcUcd2cNFlvYWx9YtnyUe3UJvPUbA50lqQ8MMvZRwL2EqXR7zorPVhL x48AArsrtlyjaFlliOckoCBJcvKOgmZ5ifkPUe2+z+QEkKbo+l+fyNHIqfhZuIP1oEnK5SlVfOJ EyY+18+MNqgqSmH01HxygN08x8xgzwGzcYyCX5eBiSA+120AbJQKAVEsiSR+VsAvaC/kdKoUIqr eQj6acJGDs3+zNMAV3XemyVyO6xS+y/WUMb6YCQE0DKLIveyL3vvB4SLLIshhhsK9uRUG3HIEoK 7jeTGuG87aXvXUx2cExtpWyav/Al6Y9m8XgP0F3DhpybiSAGPVquFs+2SJ1hWAJqOOR6a2SMN5I bg3yGDpay3ZtKny6+AWu7ef22wyTDcxJuZnZsn6MY620RMSI0E3lZbs5NmYrreUQ== X-Received: by 2002:a05:620a:1792:b0:914:ca5f:bc59 with SMTP id af79cd13be357-9153db8be70mr1156444585a.62.1780231961592; Sun, 31 May 2026 05:52:41 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9153247515esm743332185a.13.2026.05.31.05.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 May 2026 05:52:40 -0700 (PDT) Date: Sun, 31 May 2026 12:52:39 +0000 From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: Re: [PATCH v4 02/13] liveupdate: avoid mixing cleanup guards with goto in luo_session_retrieve_fd Message-ID: References: <20260530221938.115978-1-pasha.tatashin@soleen.com> <20260530221938.115978-3-pasha.tatashin@soleen.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: <20260530221938.115978-3-pasha.tatashin@soleen.com> On 05-30 22:19, Pasha Tatashin wrote: > Refactoring luo_session_retrieve_fd() to avoid mixing automated > cleanup-style guards with goto-based resource release, which is not > recommended under the Linux kernel coding style. > > Signed-off-by: Pasha Tatashin > --- > kernel/liveupdate/luo_session.c | 25 ++++++++++++------------- > 1 file changed, 12 insertions(+), 13 deletions(-) > > diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c > index 146414933977..8d9201c25412 100644 > --- a/kernel/liveupdate/luo_session.c > +++ b/kernel/liveupdate/luo_session.c > @@ -291,25 +291,24 @@ static int luo_session_retrieve_fd(struct luo_session *session, > if (argp->fd < 0) > return argp->fd; > > - guard(mutex)(&session->mutex); > - err = luo_retrieve_file(&session->file_set, argp->token, &file); > - if (err < 0) > - goto err_put_fd; > + scoped_guard(mutex, &session->mutex) { > + err = luo_retrieve_file(&session->file_set, argp->token, &file); > + if (err < 0) { > + put_unused_fd(argp->fd); > + return err; > + } > + } > > err = luo_ucmd_respond(ucmd, sizeof(*argp)); > - if (err) > - goto err_put_file; > + if (err) { > + fput(file); > + put_unused_fd(argp->fd); > + return err; > + } > > fd_install(argp->fd, file); >From Sashiko: This is a pre-existing issue, but could this error path allow userspace to hijack a recycled file descriptor? ... Answer: No. get_unused_fd_flags allocates an unused file descriptor (FD) that initially points to NULL. It is not associated with any "struct file"; this association occurs only during fd_install(), which is the final function called before returning to userspace. > > return 0; > - > -err_put_file: > - fput(file); > -err_put_fd: > - put_unused_fd(argp->fd); > - > - return err; > } > > static int luo_session_finish(struct luo_session *session, > -- > 2.53.0 >