Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3121101imw; Mon, 11 Jul 2022 02:11:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1toopw8hAFGUQyhpDUkSZ5cD8F5ckHxMnItGFOZhtnZ8/8z0lTmSE5bvAQqcJ7GGarH6/qM X-Received: by 2002:a17:906:938a:b0:726:942a:54ef with SMTP id l10-20020a170906938a00b00726942a54efmr17776977ejx.728.1657530700465; Mon, 11 Jul 2022 02:11:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657530700; cv=none; d=google.com; s=arc-20160816; b=aS0rG1kEZ2FmSkhB9Mt+4Mdf0He16fP9/aiXosJV3Th/PqKg2W/yNRbiAzx0LXbyk+ OsrnBIvINxLPHhQZUApHq05J9+odFbt+LsQ7eFFRQrx/GBw2OG6dVc7/WKZ5QPMRVvSV +v3zirgapQZm6tr0kq6YtFRljN5uZH878kCRj6yfoVYVppBeN3L7AqWHi9xOjJwqYyFw oavYbxtkKJ2wAtZTjehv+VHo3zzbNnhnBy84gd7GifWxQtjTBHxJ+UN+OwKsVXhe/YYd 6wEOzQS9fKqNygUuJIHCWrPE9nZod9+UAs+ZB3ZqUhgQuVyO2TgXvgBoUdHpGCdGIP+4 3gtw== 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=AAq+ZbX+ccp10xbLLLrYziGkdim9yKTSmeiLe84LJU0=; b=e+KeOqLnq7bXqg7/RBlkBqv+wFK0fF+FpGEJ2u+04hDcSzA+2XjCpq/1oi7WX9ca1r lvgkXqZUOGNf5IA5mNjum6BNthkrByteYs6mz6gqL4ItpCD7tqLsitAKocb/69MJnX55 LP2TTQOFIjDs/NQltV/zHZK3ibYBjI/vYA/WD01Jci1LGaFfU5MU6leWxJEcUITyHTL7 cvO/CahvlSDzJr3+befmINx7p8uEiA6jDH4W3/uAxZJTYZnmZTlnYg2ED+RgDvDFi961 K+u9lVwCBwiaOKxlKCUdGxtu8c19iNSXgbfchpgrUwSyXx/3vUfHvtE6KBfaS/nmWJyC ydBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="WR/jHOAV"; 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 gm1-20020a1709073d0100b007111f8df172si9758785ejc.271.2022.07.11.02.11.15; Mon, 11 Jul 2022 02:11:40 -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="WR/jHOAV"; 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 S230527AbiGKJH5 (ORCPT + 99 others); Mon, 11 Jul 2022 05:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231203AbiGKJHX (ORCPT ); Mon, 11 Jul 2022 05:07:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CE5022BD6; Mon, 11 Jul 2022 02:07:20 -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 B5D18B80E7A; Mon, 11 Jul 2022 09:07:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23C47C34115; Mon, 11 Jul 2022 09:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530437; bh=KSymXjj4QPiT2gWlZFuuKcVfxqVOeaPiwz4VNrrU54M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WR/jHOAV6yyEp+Ou9Zh9637DZjRUNbapxwEPFhFaCzS0ghUjJT9n1LnAVo0FkcbF/ z2WJjlYxuimqNOYuifyhEYRf+atQAtbdVYH7b2zuqF/l9QdCnNfh3Sdh987dMUx/R3 lNzMizQqNZw810vmMvaUR5gHDKWRnrybNGYXHM9E= 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 4.9 11/14] ida: dont use BUG_ON() for debugging Date: Mon, 11 Jul 2022 11:06:30 +0200 Message-Id: <20220711090535.855946471@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090535.517697227@linuxfoundation.org> References: <20220711090535.517697227@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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/lib/idr.c +++ b/lib/idr.c @@ -1124,7 +1124,9 @@ void ida_simple_remove(struct ida *ida, { unsigned long flags; - BUG_ON((int)id < 0); + if ((int)id < 0) + return; + spin_lock_irqsave(&simple_ida_lock, flags); ida_remove(ida, id); spin_unlock_irqrestore(&simple_ida_lock, flags);