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 X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88B0CC07E9B for ; Fri, 9 Jul 2021 14:19:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FEB3610E5 for ; Fri, 9 Jul 2021 14:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232263AbhGIOWh (ORCPT ); Fri, 9 Jul 2021 10:22:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231908AbhGIOWg (ORCPT ); Fri, 9 Jul 2021 10:22:36 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5916EC0613E5 for ; Fri, 9 Jul 2021 07:19:52 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id u7so12577052ion.3 for ; Fri, 09 Jul 2021 07:19:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=bhHqxUlxcu/FlkKRb/gO8lzu6xUse6jQvhbl8eFYZdk=; b=vXnEuPGUlWY0fazo+wWrLriShudF/YDNR0wefm0lD0auHy3oOVTHF8tYZRfQF7yRl4 hwEmOyY3dcLG2vRPHb/pSa3bjbZpPp5iQ65aeZ3PEOVqKPiCB/gh6d/+ajXfY1RJCqMf kRvPswJEvqRGOhBQ+vBbLHfO4tPt4oBohvOkldoRf3hukeLFkIOEcv91BasPf+spYlwf zBpaQXYJttlyVWQAkRmMXq5S9I8DuNoE8zXYw32LjoIUdiUBmYpHLBfTnwHNFqEzI37d QAljjP6FuxEFKfUjREC2TRzOUGkBnxA28j1Rns2g8w3GtBn80qqGAOSjtxZRFAJcXhrE L0Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=bhHqxUlxcu/FlkKRb/gO8lzu6xUse6jQvhbl8eFYZdk=; b=TpDGLlQ6nsS2zwiGetDxT6cSScU+pnLc/JwveWaD3kcschYyN6YE0jJuDVAlvdj8hy xoc+1wnfGMBi+cKfWbyipDHalkBkAN7wrjCqRiTC6JyH/o4TKs2rOaStUNO7v+dfn2Yh X97eXj7VlFNny1s91VdjVYa3K1cMZTXKd8aARVA0SjJQQFHILYyAtgATeGZ/cXVbmtQq HcK/2tRCXl0IKvRQBYr0NvWcSK/Ew5L1GHn4U1Vna+8IhM+GAZg7A+1YLlVH11C7st8N yyQK4NvioHTIZwlvP6pMz61xAk+FtgzBB2LCl0lKXAiM2sJXdeygsCFKUxz+Z7oQEXxV 3d3w== X-Gm-Message-State: AOAM5307WK0vZNV0/K//ukUiNzF5lQ04EwSIlQlKeJQq7z5BA6XWEz0s kT37//TmOoTfkekCpxGCVfPggyL38WEzHg== X-Google-Smtp-Source: ABdhPJy9C3+E4Cro9CTIolIQDhQ5jlejH3fxR5+yJpwB5ukwkxVCatJvDkc1mQGlvwAwKKnqqi2W2g== X-Received: by 2002:a02:c00c:: with SMTP id y12mr31977864jai.99.1625840391361; Fri, 09 Jul 2021 07:19:51 -0700 (PDT) Received: from [192.168.1.134] ([198.8.77.61]) by smtp.gmail.com with ESMTPSA id q7sm2783002ilv.17.2021.07.09.07.19.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Jul 2021 07:19:50 -0700 (PDT) Subject: Re: potential null pointer deference (or maybe invalid null check) in io_uring io_poll_remove_double() To: Colin Ian King Cc: Pavel Begunkov , io-uring@vger.kernel.org, "linux-kernel@vger.kernel.org" References: From: Jens Axboe Message-ID: Date: Fri, 9 Jul 2021 08:19:48 -0600 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: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/9/21 5:55 AM, Colin Ian King wrote: > Hi Jens, > > I was triaging some outstanding Coverity static analysis warnings and > found a potential issue in the following commit: > > commit 807abcb0883439af5ead73f3308310453b97b624 > Author: Jens Axboe > Date: Fri Jul 17 17:09:27 2020 -0600 > > io_uring: ensure double poll additions work with both request types > > The analysis from Coverity is as follows: > > 4962 static int io_poll_double_wake(struct wait_queue_entry *wait, > unsigned mode, > 4963 int sync, void *key) > 4964 { > 4965 struct io_kiocb *req = wait->private; > 4966 struct io_poll_iocb *poll = io_poll_get_single(req); > 4967 __poll_t mask = key_to_poll(key); > 4968 > 4969 /* for instances that support it check for an event match > first: */ > > deref_ptr: Directly dereferencing pointer poll. > > 4970 if (mask && !(mask & poll->events)) > 4971 return 0; > 4972 if (!(poll->events & EPOLLONESHOT)) > 4973 return poll->wait.func(&poll->wait, mode, sync, key); > 4974 > 4975 list_del_init(&wait->entry); > 4976 > > Dereference before null check (REVERSE_INULL) > check_after_deref: Null-checking poll suggests that it may be null, > but it has already been dereferenced on all paths leading to the check. > > 4977 if (poll && poll->head) { > 4978 bool done; > > pointer poll is being dereferenced on line 4970, however, on line 4977 > it is being null checked. Either the null check is redundant (because it > can never be null) or it needs to be performed before the poll->events > read on line 4970. I think it's dead code, originally copied from the single poll wake side. The 'poll' non-zero check should just go. -- Jens Axboe