Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752721AbdHQOj2 (ORCPT ); Thu, 17 Aug 2017 10:39:28 -0400 Received: from mail-io0-f175.google.com ([209.85.223.175]:37646 "EHLO mail-io0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751882AbdHQOj1 (ORCPT ); Thu, 17 Aug 2017 10:39:27 -0400 MIME-Version: 1.0 In-Reply-To: References: From: Kees Cook Date: Thu, 17 Aug 2017 07:39:26 -0700 Message-ID: Subject: Re: refactoring timers to avoid init_timer*() To: Thomas Gleixner Cc: LKML , "kernel-hardening@lists.openwall.com" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2185 Lines: 72 On Thu, Aug 17, 2017 at 7:30 AM, Thomas Gleixner wrote: > On Wed, 16 Aug 2017, Kees Cook wrote: >> In the process I noticed that we already have >> scripts/coccinelle/api/setup_timer.cocci to detect existing cases of: >> >> init_timer(t); >> t->function = func; >> t->data = data; >> >> And replace it with: setup_timer(t, func, data); >> >> Another pattern was: >> >> t->expires = when; >> add_timer(t); >> >> Which can be replaced with mod_timer(t, when); >> >> So, I've created scripts/coccinelle/api/mod_timer.cocci for the >> latter, and done a few passes with manual review. The current result >> doesn't fully eliminate init_timer() yet, but it gets much closer. I >> just wanted to be sure that this whole clean-up would actually be >> welcome before I try to nail down the last many cases. > > I think it's worth the trouble, but rather than having a gazillion of > commits with the same changelog, we should do that based on a cocci script > right before the next rc1 in one go and be done with it. > > That will cover most of the init_timer() cases and we can fixup the > remaining few oddballs manually after that. Okay, that sounds good. I'll work on improving the cocci scripts. For example, I noticed that it doesn't notice having assignments _before_ the init_timer() call: timer->function = func; timer->data = data; init_timer(timer); Whee. :) BTW, I may back off on doing ->expires = when; add_timer(timer) --> mod_timer(timer, when) changes since that actually removes a sanity check in add_timer(). My plans currently are collapsing all the open-coded init_timer*()s into setup_*timer() and then adding something like aim_timer(timer, func, data) for post-setup function/data changes. -Kees > > I just noticed that we have the same pattern with hrtimer_init(). I had a > stab on adding hrtimer_setup() and friends which takes a function argument > and converted the bulk with coccinelle. > > 82 files changed, 186 insertions(+), 210 deletions(-) > > We can do that in the same sweep as the init_timer() one and then you can > do the canary magic on hrtimers as well. > > Thanks, > > tglx > > -- Kees Cook Pixel Security