Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3671803lfo; Mon, 23 May 2022 10:59:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkA2aVVUORMBzd4frwC4Ja1u9dZJUeCvvoTb2n7Db5p2y85R0YOT7CB2vWW7v7w5l+E3nr X-Received: by 2002:a17:902:d550:b0:161:fdb8:3d9d with SMTP id z16-20020a170902d55000b00161fdb83d9dmr14422114plf.42.1653328769060; Mon, 23 May 2022 10:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653328769; cv=none; d=google.com; s=arc-20160816; b=YW1smtciFxmOcgco36MN3fN5FtZfmr0+5qgQuYbgV5j6ePxZxikoqmcHMsjDvUpbRY 96kLfpFLzFzXmiRsoOhgBb0A1OAUjWy9QGy35DxRyicgCpn58PAt8rQ8WRnc9zLHXAWL y6uvACx6tGfEVY8AXP7BzRPOhScnqd5uMNwddPoCVz+CDA98+57N8LTYKwackONsOUw0 KoiK9zKNw4mN4uI/dg3yGg0rsIExOD5T5B5XtuTQJjzjgve//Myr+AetW6TWCGGs1/Wu cLH6x54zOec085VrOZUojSvAoFaIpND9apOJilYeg6iiugJwdBf98FdgK12TooPmx+3b WEXw== 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=voroVwrWo8evtEcJlmAqnruJGQGCD74ILs+LZ15Tylc=; b=k6UHC47F11DjVD/5qYEYtAHFieRhm8xD0fD/aWQTZEXBA7i7Mz8R/ROlCPGG84fOS7 Dm9zEclqQ++KmUIVNNONGTvsPm2+jOZPmxaSAnF2J/3giopYLKMx1Tm7+NGPbIpksTuo el6OH4N4I3JLyBr4oypSlj1pScik8TQdFs43s9BUcMWvjuMx2QFbtN5DvIUBmmCZ5rcH kf4iFkAOGwzeL/RX+QPRwpLL4ywTTUsZ+mXplS38U42UZsBe1M9dKXyH+RYmU/xl0uXA K/rdlOXkOP0ci7VtTXc0VX9VhOFAYo2hCZNGy8i0T/SW95zX6Q2Wu1Ni2QpGz+pc4asn cvTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=j7GStGQj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c19-20020a056a000ad300b0050de72cfdcesi16514731pfl.74.2022.05.23.10.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=j7GStGQj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F1BC52F03E; Mon, 23 May 2022 10:56:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242510AbiEWRxC (ORCPT + 99 others); Mon, 23 May 2022 13:53:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241343AbiEWRaG (ORCPT ); Mon, 23 May 2022 13:30:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00A6443ADD; Mon, 23 May 2022 10:26:33 -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 2ABB861117; Mon, 23 May 2022 17:26:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05D0DC385AA; Mon, 23 May 2022 17:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326761; bh=cHKye3APs63Crox8rXLhOAyrVrl02kQX/7/MG+LcMoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j7GStGQjVVGHeoz416/6UN4moQsFlXukgPsXLQq24bUs3nwGUucMkDih9ZFHK4qXj qErZN6vVYsfdVeGgMxWYa9p2NoZwRxdY6OqduT2ZeoCd61pN5jtun75Pu3VxF7xIyj 7uqZv7a3+XAwYd+6gA6w89AQV5oOz24A6DGt3d6c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wander Lairson Costa , Ondrej Mosnacek , Paul Moore Subject: [PATCH 5.17 050/158] selinux: fix bad cleanup on error in hashtab_duplicate() Date: Mon, 23 May 2022 19:03:27 +0200 Message-Id: <20220523165838.999000773@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165830.581652127@linuxfoundation.org> References: <20220523165830.581652127@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=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Ondrej Mosnacek commit 6254bd3db316c9ccb3b05caa8b438be63245466f upstream. The code attempts to free the 'new' pointer using kmem_cache_free(), which is wrong because this function isn't responsible of freeing it. Instead, the function should free new->htable and clear the contents of *new (to prevent double-free). Cc: stable@vger.kernel.org Fixes: c7c556f1e81b ("selinux: refactor changing booleans") Reported-by: Wander Lairson Costa Signed-off-by: Ondrej Mosnacek Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/ss/hashtab.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/security/selinux/ss/hashtab.c +++ b/security/selinux/ss/hashtab.c @@ -179,7 +179,8 @@ int hashtab_duplicate(struct hashtab *ne kmem_cache_free(hashtab_node_cachep, cur); } } - kmem_cache_free(hashtab_node_cachep, new); + kfree(new->htable); + memset(new, 0, sizeof(*new)); return -ENOMEM; }