Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4335909pxb; Mon, 21 Feb 2022 18:19:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8A0OqthtBrRAbx/5dXmvTqypfVDbEH5EopfW654MlePe+lsu8qYzbN6NZ4ubddsvr/pBl X-Received: by 2002:a17:906:27db:b0:6cb:1f45:40fd with SMTP id k27-20020a17090627db00b006cb1f4540fdmr17600999ejc.605.1645496376471; Mon, 21 Feb 2022 18:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645496376; cv=none; d=google.com; s=arc-20160816; b=SgdHBah1WiMajhJCsa+JyLsb9KTCjtyyTz4NgtRR/Ki8aQYk85WoEPWQMyC2HWv0H4 zyg3XjaXlpZuCDIpeF8nYlVUaHpAAS7lFBktuCR1GLOz/F1tEf8uvv4XOOPwqj0DkE8C fb6ODmWt+LmRxYLLRFr41Y/gO/uh5IthYiPxTrUUkZYsaJbNT+0PT9rCM75CtBKOAgQY +dYlUcr0oXUl2IpcIgmYbdLKE1NZCDWTbyisONnULSZs4z1lANcN1YP5NC1bKjrm+jK+ WWQR+pjVAXr+hZavL3/QmIFYsQO3sfavX63tIUzfwa8ocJYYJ6PeTUWOWHRQ6E6o6Djg OtCA== 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=jYy8rN3Lp/ow96Mu0SIg6axzg2Z6hXcqn6TbQjp5BHY=; b=yEn2U7HETD99F0lPgwofKTDCzRd6WOv1a3isM1V0DtXYegHWXVdONNb230MUbRo1rh 9Z/0EmgI6+hIsK9qG7J3uSsxMoYTjrqYeJkIBUmFLD+Hv9mKnH2OhgWrIons0FT36Txg Ls4x2sRYLAfR9R+ZVlztAiQosk8jek3ohfuvfX1z/peiscXcZFpAgp9ubcMJ2wI15iTX aIz17C8R4FmIMpsUI/06C5hb5BPWRAIbzmp0meY7k3tsnatv3Zgv10yb+eKW29mvHv3k c0zYxPAkcRRR0Oou+R+6GuXmOgPsSU8H+zqTTB+lGDDPP8yiMTPe61BewUaIWRXLqkS7 fyhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qQ5rGSFD; 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 27si9664696eja.681.2022.02.21.18.19.12; Mon, 21 Feb 2022 18:19:36 -0800 (PST) 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=qQ5rGSFD; 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 S1351257AbiBUJoX (ORCPT + 99 others); Mon, 21 Feb 2022 04:44:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351261AbiBUJgz (ORCPT ); Mon, 21 Feb 2022 04:36:55 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30FF62DD40; Mon, 21 Feb 2022 01:15:32 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 40C58CE0E86; Mon, 21 Feb 2022 09:15:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27308C340E9; Mon, 21 Feb 2022 09:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645434927; bh=mzGSdJmD5/dnOJXtGDmHaV67N64Mrzt+4+mNCYQzK/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qQ5rGSFDhkmGYv6ycbe3nglgJyQS5u7F+uOweZqOhiVriEb7Hc4TMGhkgktg7LCGo EkQyqZjIe1GzrNiNCnzFBNLU4OKybKFQKcel/yMrbWnsppHKPZEbPXav1i3fVCLCo3 RrSOxBNqrMREX4CnZOcyFlJEDbU1/WxVrkApMP7g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu Zhao , Alexey Gladkov , "Eric W. Biederman" Subject: [PATCH 5.15 179/196] ucounts: In set_cred_ucounts assume new->ucounts is non-NULL Date: Mon, 21 Feb 2022 09:50:11 +0100 Message-Id: <20220221084936.939443320@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084930.872957717@linuxfoundation.org> References: <20220221084930.872957717@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.1 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: Eric W. Biederman commit 99c31f9feda41d0f10d030dc04ba106c93295aa2 upstream. Any cred that is destined for use by commit_creds must have a non-NULL cred->ucounts field. Only curing credential construction is a NULL cred->ucounts valid. Only abort_creds, put_cred, and put_cred_rcu needs to deal with a cred with a NULL ucount. As set_cred_ucounts is non of those case don't confuse people by handling something that can not happen. Link: https://lkml.kernel.org/r/871r4irzds.fsf_-_@disp2133 Tested-by: Yu Zhao Reviewed-by: Alexey Gladkov Signed-off-by: "Eric W. Biederman" Signed-off-by: Greg Kroah-Hartman --- kernel/cred.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/kernel/cred.c +++ b/kernel/cred.c @@ -676,15 +676,14 @@ int set_cred_ucounts(struct cred *new) * This optimization is needed because alloc_ucounts() uses locks * for table lookups. */ - if (old_ucounts && old_ucounts->ns == new->user_ns && uid_eq(old_ucounts->uid, new->euid)) + if (old_ucounts->ns == new->user_ns && uid_eq(old_ucounts->uid, new->euid)) return 0; if (!(new_ucounts = alloc_ucounts(new->user_ns, new->euid))) return -EAGAIN; new->ucounts = new_ucounts; - if (old_ucounts) - put_ucounts(old_ucounts); + put_ucounts(old_ucounts); return 0; }