Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3179095imw; Mon, 11 Jul 2022 03:40:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uPphQ0ytOY2ZhLfkpMfugl8E5UmBxtPB0bIUVbNiViO24PjHlxf9Qfo5aA4rL2/Cj5gBjV X-Received: by 2002:a63:ec15:0:b0:412:6fb4:88fb with SMTP id j21-20020a63ec15000000b004126fb488fbmr15108966pgh.49.1657536015230; Mon, 11 Jul 2022 03:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657536015; cv=none; d=google.com; s=arc-20160816; b=Ev03DZzKGESutLSktKF1lJ99j5Get+d4mzq0Cw3PQlbTyt0xphBzclRPMgbUj2E0/c HqKwmt+Rasy96tkhUnlZAJaI0awlrGHIuJ4G0DNGiX3NFF4VhF0LCUYd/4ytRD5sKRTX CeThEkSyHBAiNrNelX9CMXgoYWO2bPUITaVA0s+sPBOTWL7ZyO1eSCbNNQxTVpy47CxA tki7iAznE/dpVcJotKIQ7FDJEWO00kNY/AKTWddVRUEIYpY6xTmuroMKketiMzhHQUPD r3EGQ5N1Rzuu7RqyZgMvP3p3q/6fEJ/uwzoz8H0XbY3kVSljZolDKG3OIxGfuwhgt3HM /+kA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=t5/JiCxSyKD/f5X4znKHRuvleguBDBti5dgt/USjgVw=; b=G2C5cSSGrPw7bnf7H5yrOj3O2tthOKoX3JvpC55igwGcrwGZVm0mJaINafntbmobC6 H9HSGDyQ5P9v+v/QjCsP4KvlrtMEJ7422AdJhSzOyntPd9O5Eb+cSiFMmC/uUOWm2eU/ IAx1gfYGH0h4VH4o04KBF+hyhj6866eixRERdx2/EmF0EKPkB+DgkDEvoSH816HBa06X 0jdvKn9TVzdUcCBhXtVyhDf74GKIhNBL/9l8JFpdV5/vY4FD8DZzNs8PoKpjvNkZgpgI gQrGXg+ykwwbTwNrwKbcgyQB0FGFFJQvchro6GfsiiOsl1ybTfA4nnDP4d6qx548QlSm XvIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xNkXKI6u; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s82-20020a632c55000000b0040cf84add25si10285363pgs.878.2022.07.11.03.40.01; Mon, 11 Jul 2022 03:40:15 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=xNkXKI6u; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232070AbiGKJX4 (ORCPT + 99 others); Mon, 11 Jul 2022 05:23:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231959AbiGKJXN (ORCPT ); Mon, 11 Jul 2022 05:23:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5DEF5BD; Mon, 11 Jul 2022 02:13:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6C9ACB80D2C; Mon, 11 Jul 2022 09:13:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2F32C34115; Mon, 11 Jul 2022 09:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530823; bh=T7xOkgvjtE3PbkwxKocejNJRefdrZpo1wFeudSfDjeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xNkXKI6uakFcZikxiliwddPPR9ZqkUYezsixZf+kIPaKiHLEuYiACy3uzTvQnZpSj kAtwyvdU9AZfEl38Zka8MVRjZUlXz190HwjMuILt1FqDQ1AoJMWAeWUrf/481MHELi OMlISDg1a4xnn7QNPkqNRVaVUs7LnGP7pMJmCeME= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Itay Iellin , Matthew Wilcox , Linus Torvalds Subject: [PATCH 5.10 51/55] ida: dont use BUG_ON() for debugging Date: Mon, 11 Jul 2022 11:07:39 +0200 Message-Id: <20220711090543.258212313@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090541.764895984@linuxfoundation.org> References: <20220711090541.764895984@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Linus Torvalds commit fc82bbf4dede758007763867d0282353c06d1121 upstream. This is another old BUG_ON() that just shouldn't exist (see also commit a382f8fee42c: "signal handling: don't use BUG_ON() for debugging"). In fact, as Matthew Wilcox points out, this condition shouldn't really even result in a warning, since a negative id allocation result is just a normal allocation failure: "I wonder if we should even warn here -- sure, the caller is trying to free something that wasn't allocated, but we don't warn for kfree(NULL)" and goes on to point out how that current error check is only causing people to unnecessarily do their own index range checking before freeing it. This was noted by Itay Iellin, because the bluetooth HCI socket cookie code does *not* do that range checking, and ends up just freeing the error case too, triggering the BUG_ON(). The HCI code requires CAP_NET_RAW, and seems to just result in an ugly splat, but there really is no reason to BUG_ON() here, and we have generally striven for allocation models where it's always ok to just do free(alloc()); even if the allocation were to fail for some random reason (usually obviously that "random" reason being some resource limit). Fixes: 88eca0207cf1 ("ida: simplified functions for id allocation") Reported-by: Itay Iellin Suggested-by: Matthew Wilcox Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- lib/idr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/lib/idr.c +++ b/lib/idr.c @@ -491,7 +491,8 @@ void ida_free(struct ida *ida, unsigned struct ida_bitmap *bitmap; unsigned long flags; - BUG_ON((int)id < 0); + if ((int)id < 0) + return; xas_lock_irqsave(&xas, flags); bitmap = xas_load(&xas);