Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3164724imw; Mon, 11 Jul 2022 03:18:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1skVLdwMDu1TBBFDcOvkbNjECb7vDwTAWjkh+ZisuMQSZyYGvCVEw0tVvGSeE/mAgxYzLMH X-Received: by 2002:a05:6a00:1501:b0:525:79a7:aa4 with SMTP id q1-20020a056a00150100b0052579a70aa4mr17862442pfu.44.1657534720507; Mon, 11 Jul 2022 03:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657534720; cv=none; d=google.com; s=arc-20160816; b=GbAjXPCkV0Q1HadhVdUiQvXhSxGx+H2o34ixDwrPc+bRX+h++A6ga1Xs985xd0GjsC YiXIe1clu+iiMzhSqspm3GqYFGZd9S+ya5rdEQvMzXI/lInMstQsf6vHiqLvSx1SR38k nCLHRIF6Cl5H/978EOvAjp4us796yq54G3zcSeqaQoydwPMCQkiHBKyXIFxpkyeNsrnj cAhPyz41sNPdj4zee8aGMBahJxsniNmQtNvMHSQlsMeTFlIqqB8twb0lPKwJ96l+lrTl cMqoGUzUVbzgoEyUtBeSeyUdCH3xSfH3zbVOibXyy4A572Idcq4j6f7LpAp/5B5JcRAg YuOQ== 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=xJLy1M4I2QrJVpD0FVRa01mem7eb/yopy463bsZR/L4=; b=aSaeYB2m91Vz3/hYxjb3AHuieWy/VqqDiQPfKg8SFJpeENV3VML1FSSF8IlKdBWBv4 3mYPMoxFSp4ENCROWpscCQao0NX8U491JcKb0fja5E6Y5T+x93VrbUvVaXYnlG3hi84u QQX2KvSf0DM5OIvCFyc3deGh6wshOzwQdtUZYu4SFnK8ySNWSt6g6M/z30W8FiM40RMg D3ZFJsY6ZX//5AZzIl/BnjSENr/PfM1P+5G8jO4rTzj+OG40XUK4PtjMSwbWUfbStHrm 5WfXhoi1YzRtgHIciIPJKplcx6Xmkn2opwb3/IevjTUAFFq1kOdI3imgdFEIUIfkwpZd k10Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=itdkMG6J; 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 w12-20020a170902d70c00b001640824e7d3si8409667ply.152.2022.07.11.03.18.21; Mon, 11 Jul 2022 03:18: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=itdkMG6J; 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 S230180AbiGKJJG (ORCPT + 99 others); Mon, 11 Jul 2022 05:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbiGKJIV (ORCPT ); Mon, 11 Jul 2022 05:08:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF8F6255A0; Mon, 11 Jul 2022 02:07:46 -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 dfw.source.kernel.org (Postfix) with ESMTPS id F3D4C61183; Mon, 11 Jul 2022 09:07:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09DD0C34115; Mon, 11 Jul 2022 09:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530465; bh=lPdGCGY4nCPJiAo2k5l1xKVFPxrsnk/2+JWwawIClYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=itdkMG6JjUujmTh/CDihpCuzpBdkUTy+uA6c0T6DFTB1BPStItwjfE5M+fFf2byZE mIW6Y0xWDky4/ulsFTFqtqmLECbCeOYpb5qumGuThJAktZIQ+8s7imejawvgbdBkHn 5tpbvb7cMc4kF0lUukb0HGfRof9C1w2RDUJYolj0= 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.14 14/17] ida: dont use BUG_ON() for debugging Date: Mon, 11 Jul 2022 11:06:39 +0200 Message-Id: <20220711090536.687509539@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090536.245939953@linuxfoundation.org> References: <20220711090536.245939953@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 @@ -498,7 +498,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);