From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) by gnuweeb.org (Postfix) with ESMTPS id 20EA17E24F for ; Mon, 7 Feb 2022 15:37:55 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=kernel-dk.20210112.gappssmtp.com header.i=@kernel-dk.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=48XlmHJS; dkim-atps=neutral Received: by mail-io1-f49.google.com with SMTP id c188so17242027iof.6 for ; Mon, 07 Feb 2022 07:37:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=OVQkazA38Xs9TAErBTjWdO6iUtOuwl/winaYJ9o81FU=; b=48XlmHJS3i0F3tDt8IW0RPM3YClhDQwRwMrwLBb2zN9KGmi6BULuL/eoN60AZtMDTp dI9oc4EWlTAyVpe9OK+NVU2RFXFVZ+n70oJwyW+EW1xkrBX/+ZJ/ibA/qOCBcMpE+WqK etwyeVa2uJjc26Wckq74cCNHsYm5qebX8cDv3FiJLbqNnKUleCh5i92zCtCdzh/NYocQ nmyCcJ2iGPu/K+wD/njpw0wjqBKzP6J9AwMqZ72ptG6zZSAeXNzg+SzEuTnvogeWGAQi kKlCsRrcdujp4G/usKOvDv3eCoaouB7/HjNgymyeIt21prhZflRIDdRjMmj2bxQiB3+E tH1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OVQkazA38Xs9TAErBTjWdO6iUtOuwl/winaYJ9o81FU=; b=wuUO63wwHu8vbdrtKpZVh6yW6nSMXgNM1PIznrf2+77fdJbDwzjsAoMRETUdEo5Frx UL37AqOF8hyUdtzlYzf1BRPYMBGkvmvf87cK+reVgcZ+vPF/uLYCjQrrrpU9CYeViZVA N/fUhvahJKa7sMGSkNFv0B8AbyN8tEqypQ9lk41BLOXmMoG+Q0YDRW9Ngr5xbi8gmL1e v+OY8M6rgQYkpqxtTx8p/XX/GUdhY8vYOHefeot/+4FYwa7+83mb6nl3arviu7WLOMnS VINIsyxmX2jdSt0Ygff0xoYyuQKv8JgYnFbj+ELHVyt6CQ8tgXZJlR9t6xo+Wv5gDbG6 tjxw== X-Gm-Message-State: AOAM533KRJ1b8G8KLq4vEeAEcxrwt0VnvkGBbpZu3H/YZrYyrLxXB34H VUkWvMfe8yEfk4ljcS/KVQsDXQ== X-Google-Smtp-Source: ABdhPJwEVJPTtO4O5g1aR8TU5u2jGY2/Fd+8lMSh+MkotBvUoDaXZ/ULqHa0zOSCIghSgzPfUnSPKA== X-Received: by 2002:a05:6638:1305:: with SMTP id r5mr112912jad.154.1644248273876; Mon, 07 Feb 2022 07:37:53 -0800 (PST) Received: from [192.168.1.30] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id p11sm6431831iov.38.2022.02.07.07.37.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Feb 2022 07:37:53 -0800 (PST) Subject: Re: [PATCH io_uring-5.17] io_uring: Fix build error potential reading uninitialized value To: Alviro Iskandar Setiawan , Dan Carpenter Cc: Ammar Faizi , GNU/Weeb Mailing List , io-uring Mailing list , Tea Inside Mailing List , Linux Kernel Mailing List , kernel test robot , "Chen, Rong A" , Pavel Begunkov References: <20220207114315.555413-1-ammarfaizi2@gnuweeb.org> <91e8ca64-0670-d998-73d8-f75ec5264cb0@kernel.dk> <20220207142046.GP1978@kadam> From: Jens Axboe Message-ID: Date: Mon, 7 Feb 2022 08:37:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: On 2/7/22 7:33 AM, Alviro Iskandar Setiawan wrote: > On Mon, Feb 7, 2022 at 9:21 PM Dan Carpenter wrote: >> On Mon, Feb 07, 2022 at 06:45:57AM -0700, Jens Axboe wrote: >>> On 2/7/22 4:43 AM, Ammar Faizi wrote: >>>> 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. >>> >>> The compiler should be able to deduce this, and I guess newer compilers >>> do which is why we haven't seen this warning before. > > The compiler can't deduce this because the import_single_range() is > located in a different translation unit (different C file), so it > can't prove that (ret < min_ret) is always true as it can't see the > function definition (in reality, it is always true because it only > returns either 0 or -EFAULT). Yes you are right, I forgot this is the generic helper, and not our internal one. >> No, we disabled GCC's uninitialized variable checking a couple years >> back. Linus got sick of the false positives. You can still see it if >> you enable W=2 >> >> fs/io_uring.c: In function ‘io_recv’: >> fs/io_uring.c:5252:20: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized] >> } else if ((flags & MSG_WAITALL) && (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { >> ~~~~~~~^~~~~~~~~~~~~~ >> >> If you introduce an uninitialized variable bug then likelyhood is the >> kbuild-bot will send you a Clang warning or a Smatch warning or both. >> I don't think anyone looks at GCC W=2 warnings. >> > > This warning is valid, and the compiler should really warn that. But > again, in reality, this is still a false-positive warning, because > that "else if" will never be taken from the "goto out_free" path. Right, as mentioned in my email, there is no bug there. But I do like the patch as it cleans it up too, the error-out path should not include non-cleanup items. -- Jens Axboe