Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp501498pxb; Mon, 7 Feb 2022 17:06:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIXaoVNL9dVFDZtHCWEPG0CBeFMKPv0eAficHYfFwfGzWmCN4e1ziHMvUpDpgLdBaojkd1 X-Received: by 2002:a05:6402:4385:: with SMTP id o5mr2143651edc.48.1644282375389; Mon, 07 Feb 2022 17:06:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644282375; cv=none; d=google.com; s=arc-20160816; b=xsMipuvaHqMnKb7T+GRe5CJmPXPdYQ/qbpHNuYVhAuP+tUIPsKiwBIKsfMW4pecFOE KZjOMBfDEuozGVH6oJ+FHSjKlXci5PYozya2ciz+DztPN8ZiRtlbDItWjPfMC1fBGMmu fZdBsL+bide/43aZqlZKXEqV1kJUGZO5aaIUog6ibwI/7YS39s1hAl5E34Mpzxl345f4 g1wIakHr9TUdiH6UcmDcgThuOW+OocNjAIWwPvvd+1uQZBNND55TzhruXRwglFfLmY9K +VI/fYeDfZEIQVYj6pNq9pngP+Dhd5S2xV4I20C+irOGJY/v6Glfy/nUXrtXxSeBMpPX Ru0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=OVQkazA38Xs9TAErBTjWdO6iUtOuwl/winaYJ9o81FU=; b=T8pxNr2DbBHywmJ/4lBQQIZrKTagFmWYHDqdnSSA11tNXh/7XcU+rklr8yn9BJy5s+ 2HwFq7OwiICMztondjmTsIoHhcGrHAC35q8exu1Sc/q2CL5rBVwO+XGRWRymRAE3RiAm o8LRTQhXuuIiiTD8lqTDx66fyUfOC9zoHxb/BRP28SFoWk7ThP/Rlf23g9v233MSSmIV 0NQON3pwmVgjlAYzn97omqbsaKbPhKSlnSW9rLzqKeDbJaaK8vuMPlHe2oxmuRdVhmxw t/ie9ElsIVvkcjeUlqFKzpLj09cF6wS5A2+g9kXyg66SrfiQxcCP5K+Z11OYVzJ5xhKX TjiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=48XlmHJS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j18si9317104edw.229.2022.02.07.17.05.49; Mon, 07 Feb 2022 17:06:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=48XlmHJS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383598AbiBGPnK (ORCPT + 99 others); Mon, 7 Feb 2022 10:43:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345227AbiBGPhz (ORCPT ); Mon, 7 Feb 2022 10:37:55 -0500 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E956C0401CA for ; Mon, 7 Feb 2022 07:37:54 -0800 (PST) Received: by mail-io1-xd2f.google.com with SMTP id h7so17256350iof.3 for ; Mon, 07 Feb 2022 07:37:54 -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=wH2up6uHHq8kNvk2B4bq90gdbX5ZkIL0C7S7iihUVNO28HAP+3CTuNjRxmiRXCp3X+ wHdJZRTwm0U8+QKhQLXPwOM76g6HSIOZ+AHKOLSemwoTzC1enOyXz0U6WnAdijTM9xeu 6vXJjJClim8FruUPR3I/TWgC3JqBqPGW9ZNqHRBs2I0w41clv6GFIa6AOLO5ImGvZUvN fpvAdtqwQZnpod8i1uyNoAL1NNM44af2b6C1kc633HzOLi/IhX2+XWeuItjywnN/4VbY bt9qOUuAj2ElsqccUtLM7xc6gm/ExNSylt8wqx7+eOGZYEjqlQZm0Yhglqb01i872n1s cd3A== X-Gm-Message-State: AOAM531U5IKnkYiyhea40ZdHlIOXU215AUOefTwlVYuRO2YXXlSMjvkn kG+EcbZIFDZQkB9iAL+5bpVhrQ== 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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