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=-7.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 14A7AC4727E for ; Wed, 7 Oct 2020 18:12:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 782F92173E for ; Wed, 7 Oct 2020 18:12:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HD/l7WlD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728808AbgJGSME (ORCPT ); Wed, 7 Oct 2020 14:12:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727304AbgJGSME (ORCPT ); Wed, 7 Oct 2020 14:12:04 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13907C0613D2 for ; Wed, 7 Oct 2020 11:12:04 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id o9so1390384plx.10 for ; Wed, 07 Oct 2020 11:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=U51R3R0x1HlDU/rwfEcnqrw14Df1DxhtYwUuphhicTo=; b=HD/l7WlDsgTbjiMNQseskrrD3WamWgf+2tA58r3lFd72ZBZ4ncrD3IWyow15G+CJhg Y7naLw1dtmz4H13LtnKtTtXr5tFXOJ/OAJUnM1drGRS7MrOr22aFhGLSgDaESWo8ZNr6 cyLCWLelwiKdaT4+U4LRUez+2R3Li2Fz5/BUs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=U51R3R0x1HlDU/rwfEcnqrw14Df1DxhtYwUuphhicTo=; b=ZVAflkksMom0cuStUxhJyj6MkfGKVN92tgFYLVZ4RnCvtD0fFq0R+815NWWI+gxRPE Oc3aw1IbNgc5LLr4MF7aDDKBYPJhR2xsToW4gyxAuUMhw1GDzaxaVlfdGzTCWyXYSaEo fnqTZ2sQBFCHkTz914o/x+B9k9xt6TQNmGyRLZTaW/xNNIrp6ocJ53A6pjpMHCWZcvZl bt62pbsUoGa7y3JhQa2h6lyVWIG6w0Gcc/IGz4XfpgoPYjqUe8lFuBRTUuTiY2PprnZU c+m3WtWQktPMXcx0r1XwXw+/EqnyKWOW+euI8i6qaq4dHI6dglUjz5AYBu2VESD2YoHA snKw== X-Gm-Message-State: AOAM5311RMrVikMH5AE34KOAZ2mX5RqgovroXP3UhSF8rq5X/g3BmRMp XfHb1SqYZTSIhwYhKxjJpIvSULSPNYAj4VIk X-Google-Smtp-Source: ABdhPJybWHoqusi93W9Aq6yodO08L83RzLwuH6q440Ymxn5QdLI/Kyd7aRpJaYbzEXCVsMdsAl0y+w== X-Received: by 2002:a17:902:c3c5:b029:d3:df24:1ffb with SMTP id j5-20020a170902c3c5b02900d3df241ffbmr3979932plj.35.1602094323642; Wed, 07 Oct 2020 11:12:03 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q2sm3810459pfu.193.2020.10.07.11.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 11:12:02 -0700 (PDT) Date: Wed, 7 Oct 2020 11:12:01 -0700 From: Kees Cook To: Shuah Khan Cc: shuah@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 02/11] selftests:lib:test_counters: add new test for counters Message-ID: <202010071111.F3968C04@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 06, 2020 at 02:44:33PM -0600, Shuah Khan wrote: > Add a new selftest for testing counter_atomic* Counters API. This test > load test_counters test modules and unloads. > > The test module runs tests and prints results in dmesg. > > There are a number of atomic_t usages in the kernel where atomic_t api > is used strictly for counting and not for managing object lifetime. In > some cases, atomic_t might not even be needed. > > The purpose of these counters is to clearly differentiate atomic_t > counters from atomic_t usages that guard object lifetimes, hence prone > to overflow and underflow errors. It allows tools that scan for underflow > and overflow on atomic_t usages to detect overflow and underflows to scan > just the cases that are prone to errors. > > Simple atomic counters api provides interfaces for simple atomic counters > that just count, and don't guard resource lifetimes. Counter will wrap > around to 0 when it overflows and should not be used to guard resource > lifetimes, device usage and open counts that control state changes, and > pm states. > > Using counter_atomic* to guard lifetimes could lead to use-after free > when it overflows and undefined behavior when used to manage state > changes and device usage/open states. > > Signed-off-by: Shuah Khan Reviewed-by: Kees Cook -- Kees Cook