From mboxrd@z Thu Jan 1 00:00:00 1970 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 B1D9FC433F5 for ; Mon, 7 Feb 2022 13:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230467AbiBGNGh (ORCPT ); Mon, 7 Feb 2022 08:06:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391445AbiBGMBt (ORCPT ); Mon, 7 Feb 2022 07:01:49 -0500 X-Greylist: delayed 210 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 07 Feb 2022 03:59:31 PST Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E917C03E921; Mon, 7 Feb 2022 03:59:30 -0800 (PST) Received: from integral2.. (unknown [36.72.213.52]) by gnuweeb.org (Postfix) with ESMTPSA id A50E97E258; Mon, 7 Feb 2022 11:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1644234255; bh=UC+l746d+ctD97nNi+ogzS1mPkamtQDrniJtWWP4aXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M8RxUq8vBDKlrMWCk6tUjzExD87kUWg+ChDGFxXP4ig7iMkkzz389ytZoZG/In1i4 DCDMeFvvZ5/7fp3IEuf/wupbvmAyPfAJnwWXpqChxyndNjM5l1PHI7QqLsyU4PJUfT V+oS8oNUo5UBy9TohgSER7tI1yEoSAaE+vBxnyiV8z5nM9ORVnG6A5ie3Wpl8BSF8Q W8G9PqVd8o+MnyfPP4LOs9iLhpUx35UfMPvADdyW1Q/bDrpkz8Sq6PW+AftCLixJBY w1S5zJ0TH8NPIOMvZfYp44I+b0XSPt4W7i4W4Zalm6M0UHJI7HN2xx23T2w+JEcGv3 rAS4mnNqq3ERQ== From: Ammar Faizi To: Jens Axboe Cc: GNU/Weeb Mailing List , io-uring Mailing list , Tea Inside Mailing List , Linux Kernel Mailing List , Alviro Iskandar Setiawan , kernel test robot , Dan Carpenter , "Chen, Rong A" , Pavel Begunkov , Ammar Faizi Subject: [PATCH io_uring-5.17] io_uring: Fix build error potential reading uninitialized value Date: Mon, 7 Feb 2022 18:43:15 +0700 Message-Id: <20220207114315.555413-1-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Alviro Iskandar Setiawan In io_recv() if import_single_range() fails, the @flags variable is uninitialized, then it will goto out_free. After the goto, the compiler doesn't know that (ret < min_ret) is always true, so it thinks the "if ((flags & MSG_WAITALL) ..." path could be taken. The complaint comes from gcc-9 (Debian 9.3.0-22) 9.3.0: ``` fs/io_uring.c:5238 io_recvfrom() error: uninitialized symbol 'flags' ``` Fix this by bypassing the @ret and @flags check when import_single_range() fails. Reasons: 1. import_single_range() only returns -EFAULT when it fails. 2. At that point @flags is uninitialized and shouldn't be read. Reported-by: kernel test robot Reported-by: Dan Carpenter Reported-by: "Chen, Rong A" Link: https://lore.gnuweeb.org/timl/d33bb5a9-8173-f65b-f653-51fc0681c6d6@intel.com/ Cc: Pavel Begunkov Suggested-by: Ammar Faizi Fixes: 7297ce3d59449de49d3c9e1f64ae25488750a1fc ("io_uring: improve send/recv error handling") Signed-off-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- fs/io_uring.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 2e04f718319d..3445c4da0153 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5228,7 +5228,6 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) min_ret = iov_iter_count(&msg.msg_iter); ret = sock_recvmsg(sock, &msg, flags); -out_free: if (ret < min_ret) { if (ret == -EAGAIN && force_nonblock) return -EAGAIN; @@ -5236,9 +5235,9 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) ret = -EINTR; req_set_fail(req); } else if ((flags & MSG_WAITALL) && (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { +out_free: req_set_fail(req); } - __io_req_complete(req, issue_flags, ret, io_put_kbuf(req)); return 0; } base-commit: f6133fbd373811066c8441737e65f384c8f31974 -- 2.32.0