Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5700612rwb; Mon, 14 Nov 2022 08:18:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf6oae/IjCFYf6gnh4Ry3jBr+6FSMCNFxwKfpnwzbBBH6gqFSxoa+SmkrZpYRNfg59sA//E1 X-Received: by 2002:a17:906:5f88:b0:7ad:92fa:589e with SMTP id a8-20020a1709065f8800b007ad92fa589emr10388285eju.668.1668442725191; Mon, 14 Nov 2022 08:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668442725; cv=none; d=google.com; s=arc-20160816; b=upke/MiAva2nNKNFgT+M2oeFN6RMUU53vskoyiicf+iE7V6pTnGB1hCen5Y15yCcfg avpk6VLV6NEbIbP/H+AsyKOiTbwDzxOwACocZfej3l5jo45sxzmirGOf58OkHGthecrW mMRdVDv/VuOxz3ULv8xwjoTYGP1KxMFQrzY1DKxufUIMETrkkNkqxgkVlTY/Nj/X3Eca DDxz0TAikv5G0VoGhSYU/ExsvPHlLpkA5DTCSx1lJK2ZWmSpFPIXcPNhk5/f4tdWpI81 xctMt8cpf3H+Iqextk+aTjVIU0f9lXZehjF/sPJEe9TzpYpYP88RoCW8z3sPsZyRrqu6 F0UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=D9pd/GSe7CysleXLWr8DdYAfbfFA6TQ9To8qlC4a4rk=; b=BTvU2AVapisyBVK+zwcPH25/gfPNlms0vJUiOZnhqvw1lxZzCAav9Db0GF/lF2BXs3 4wfot8WonHy+fryUAkmk8G96vHE3Q7KxL3/uHbpFzkZBZw0U+2GVkrrAshtJqt3luJLZ dhJE7D+zp75PCvg7NzBXqLwHNUPBGwryB8r8eg9n7zI9Fgu+NosGpdmhlWodSUFHlcqe Hm2jsTcJMvwn2K6kBV4a2/tez6eo+J+R9kp0362tgdyUpve4S0c94iWZ9U0lIQoPkvdJ pDDqRkeinSmtVA8MkujkZt0jaHpVnNnl01OFg1dw5OmMIDFlR/xhJanDgHBfq8YzTEwL arWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=Rn8IPitL; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne39-20020a1709077ba700b007ade8dd3517si10387495ejc.936.2022.11.14.08.18.22; Mon, 14 Nov 2022 08:18:45 -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=@protonmail.com header.s=protonmail3 header.b=Rn8IPitL; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236117AbiKNPyo (ORCPT + 87 others); Mon, 14 Nov 2022 10:54:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237264AbiKNPym (ORCPT ); Mon, 14 Nov 2022 10:54:42 -0500 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D202DAB5 for ; Mon, 14 Nov 2022 07:54:40 -0800 (PST) Date: Mon, 14 Nov 2022 15:54:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1668441276; x=1668700476; bh=D9pd/GSe7CysleXLWr8DdYAfbfFA6TQ9To8qlC4a4rk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Rn8IPitLRkNTeAiCB0IPjpZPDAsxlcfaIyE0cGg/qwLwfGvY/2IwysoWqJJq70lZc E/PnYLiFMqPRdDOD13xdoZzXf44rH+rt4nyRVplVL9heFWLdWV9mOW3Sk8XSka+JPY Q1DIJq57RZ7JkG0XVXkXgqjPgs6J2ruoZKiawMjI5Rzj+WiEOiInLQhgIZl6GcJsvX lRE4DN2zM5WuAn23FLfGBDRrH/y7tUfwMGLSZZzXF85RBluSA9j+9YebhHhfIRPIZL LjvyeeCsES8EJPCylvWj9ROVWTmtRCLvpRg5z8Rh7bjgATnvCLF88BsOhqRsYCd7VV fSOpb8ehA1NbQ== To: Thomas Gleixner From: =?utf-8?Q?Barnab=C3=A1s_P=C5=91cze?= Cc: linux-kernel@vger.kernel.org, John Stultz Subject: Re: [PATCH v1] timerqueue: use rb_entry_safe() in timerqueue_getnext() Message-ID: In-Reply-To: <87v8nis83n.ffs@tglx> References: <20221027212506.3745164-1-pobrn@protonmail.com> <87v8nis83n.ffs@tglx> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS 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 Hi 2022. november 14., h=C3=A9tf=C5=91 1:17 keltez=C3=A9ssel, Thomas Gleixner = =C3=ADrta: > On Thu, Oct 27 2022 at 21:37, Barnab=C3=A1s P=C5=91cze wrote: >=20 > > When `timerqueue_getnext()` is called on an empty timerqueue > > the returned rb_node pointer will be NULL. Using `rb_entry()` > > on a potentially NULL pointer will only - coincidentally - work > > if the offset of the rb_node member is 0. This is currently the > > case for `timerqueue_node`, but should this ever change, > > `timerqueue_getnext()` will no longer work correctly on empty > > timerqueues. To avoid this, switch to using `rb_entry_safe()`. >=20 > I agree with the change but not with the argumentation above. >=20 > Whatever the current offset of node is does not matter at all, > really. This is a blantant missing NULL pointer check which works by > chance. >=20 > So there is no weasel wording justfied about "coincidentally" and "might > not longer work correctly". >=20 > Just spell it out that this is a blantant bug and nothing else. I agree, I was just trying to describe why it has not caused any issues yet= . Would this be better? When `timerqueue_getnext()` is called on an empty timer queue, it will use `rb_entry()` on a NULL pointer, which is invalid. Fix that by using `rb_entry_safe()` which handles NULL pointers. =20 This has not caused any issues so far because the offset of the `rb_node` member in `timerqueue_node` is 0, so `rb_entry()` is essentially a no-op. >=20 > Back then when that code got introduced rb_entry_safe() did not exist at > all so it's even more obvious that this is simply a missing NULL pointer > check, right? As far as I can tell it did exist and it was actually used when the offending change was committed (511885d7061e). >=20 > This also requires a Fixes: tag which flags the commit which introduces > this bug. >=20 > Thanks, >=20 > tglx >=20 Regards, Barnab=C3=A1s P=C5=91cze