From patchwork Tue Apr 26 08:21:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 566497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6599C433FE for ; Tue, 26 Apr 2022 09:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346111AbiDZJK7 (ORCPT ); Tue, 26 Apr 2022 05:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347922AbiDZJGX (ORCPT ); Tue, 26 Apr 2022 05:06:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80ED1B7C62; Tue, 26 Apr 2022 01:47:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 11D4860C42; Tue, 26 Apr 2022 08:47:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D299C385A4; Tue, 26 Apr 2022 08:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962839; bh=eU63M2Csqic/VCKHXYjcooxY2JHvdkP4DRhbEDkReXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oni03q3bRQ7nKMcCOJU6YZkBYJM4FwrQEsMmHFRYk+dP2BFEWpX16Lmq63Jwuosw0 Ao4SesoHEYQ/P+pB8UhmltuNFY1F9X8m2YG/LNqHhDmTZovA9VuNnW2cazUDtZfvJg X6iCaw/XKb+8TgSDZsRSfZMKjbKmxNzIKqlxJWgs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+96b43810dfe9c3bb95ed@syzkaller.appspotmail.com, Jens Axboe , Sasha Levin Subject: [PATCH 5.17 099/146] io_uring: free iovec if file assignment fails Date: Tue, 26 Apr 2022 10:21:34 +0200 Message-Id: <20220426081752.842825330@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081750.051179617@linuxfoundation.org> References: <20220426081750.051179617@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jens Axboe [ Upstream commit 323b190ba2debbcc03c01d2edaf1ec6b43e6ae43 ] We just return failure in this case, but we need to release the iovec first. If we're doing IO with more than FAST_IOV segments, then the iovec is allocated and must be freed. Reported-by: syzbot+96b43810dfe9c3bb95ed@syzkaller.appspotmail.com Fixes: 584b0180f0f4 ("io_uring: move read/write file prep state into actual opcode handler") Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 619c67fd456d..9349d7e0754f 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3622,8 +3622,10 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags) iovec = NULL; } ret = io_rw_init_file(req, FMODE_READ); - if (unlikely(ret)) + if (unlikely(ret)) { + kfree(iovec); return ret; + } req->result = iov_iter_count(&s->iter); if (force_nonblock) { @@ -3742,8 +3744,10 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags) iovec = NULL; } ret = io_rw_init_file(req, FMODE_WRITE); - if (unlikely(ret)) + if (unlikely(ret)) { + kfree(iovec); return ret; + } req->result = iov_iter_count(&s->iter); if (force_nonblock) {