From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57829FA3742 for ; Thu, 27 Oct 2022 12:07:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235535AbiJ0MHb (ORCPT ); Thu, 27 Oct 2022 08:07:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235475AbiJ0MHa (ORCPT ); Thu, 27 Oct 2022 08:07:30 -0400 X-Greylist: delayed 321 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 27 Oct 2022 05:07:29 PDT Received: from mx.cjr.nz (mx.cjr.nz [51.158.111.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 875E4923E8; Thu, 27 Oct 2022 05:07:29 -0700 (PDT) Received: from authenticated-user (mx.cjr.nz [51.158.111.142]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pc) by mx.cjr.nz (Postfix) with ESMTPSA id AB86B7FC01; Thu, 27 Oct 2022 12:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cjr.nz; s=dkim; t=1666872124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MtpMGCF+iBRpVLWgZ5Ofi84bzkswm5lge9Z3x2eJ++g=; b=cGaSQswDbxqhSBVj5pDq2GqhsfWTvLHXYYkMfnzUtzDu9qQoJIAheeOJh6kvSpEf5GvfRG yRGEyPPCKVdpWf1B+kLxd0W9HSAJYK3NXUHVB/UXVrRGK19eRMFPdAp2TDyRAJrxZA4/mG PbyYULxDaGdOHhPFJ1IGHC4xcjeMA0QplsS66eLO39jSdLEjsA2Zfgar8lFMkwj6RRssS7 WLUOcZngyyy5D2hJe4t1LhQrRm+4Ofop0TJ6lZWko/2wplsv9yIzIFYLYBhtes4EMzg4nM CFzFh2tBjwghTEY1OzCuUpw850fnEkoZ26nkvczAP3RB+X5CfnZRv2jHEMHE/g== From: Paulo Alcantara To: Kees Cook , "Eric W. Biederman" Cc: Kees Cook , David Howells , Luis Chamberlain , Russ Weight , Greg Kroah-Hartman , "Rafael J. Wysocki" , Steve French , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Namjae Jeon , Sergey Senozhatsky , Trond Myklebust , Anna Schumaker , Chuck Lever , Jeff Layton , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Michal =?utf-8?Q?Koutn=C3=BD?= , Peter Zijlstra , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] cred: Do not default to init_cred in prepare_kernel_cred() In-Reply-To: <20221026232943.never.775-kees@kernel.org> References: <20221026232943.never.775-kees@kernel.org> Date: Thu, 27 Oct 2022 09:03:08 -0300 Message-ID: <87bkpxh3sz.fsf@cjr.nz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Kees Cook writes: > A common exploit pattern for ROP attacks is to abuse prepare_kernel_cred() > in order to construct escalated privileges[1]. Instead of providing a > short-hand argument (NULL) to the "daemon" argument to indicate using > init_cred as the base cred, require that "daemon" is always set to > an actual task. Replace all existing callers that were passing NULL > with &init_task. > > Future attacks will need to have sufficiently powerful read/write > primitives to have found an appropriately privileged task and written it > to the ROP stack as an argument to succeed, which is similarly difficult > to the prior effort needed to escalate privileges before struct cred > existed: locate the current cred and overwrite the uid member. > > This has the added benefit of meaning that prepare_kernel_cred() can no > longer exceed the privileges of the init task, which may have changed from > the original init_cred (e.g. dropping capabilities from the bounding set). > > [1] https://google.com/search?q=3Dcommit_creds(prepare_kernel_cred(0)) > > Cc: "Eric W. Biederman" > Cc: David Howells > Cc: Luis Chamberlain > Cc: Russ Weight > Cc: Greg Kroah-Hartman > Cc: "Rafael J. Wysocki" > Cc: Steve French > Cc: Paulo Alcantara > Cc: Ronnie Sahlberg > Cc: Shyam Prasad N > Cc: Tom Talpey > Cc: Namjae Jeon > Cc: Sergey Senozhatsky > Cc: Trond Myklebust > Cc: Anna Schumaker > Cc: Chuck Lever > Cc: Jeff Layton > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: "Michal Koutn=C3=BD" > Cc: Peter Zijlstra > Cc: linux-cifs@vger.kernel.org > Cc: samba-technical@lists.samba.org > Cc: linux-nfs@vger.kernel.org > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook > --- > drivers/base/firmware_loader/main.c | 2 +- > fs/cifs/cifs_spnego.c | 2 +- > fs/cifs/cifsacl.c | 2 +- > fs/ksmbd/smb_common.c | 2 +- > fs/nfs/flexfilelayout/flexfilelayout.c | 4 ++-- > fs/nfs/nfs4idmap.c | 2 +- > fs/nfsd/nfs4callback.c | 2 +- > kernel/cred.c | 15 +++++++-------- > net/dns_resolver/dns_key.c | 2 +- > 9 files changed, 16 insertions(+), 17 deletions(-) Acked-by: Paulo Alcantara (SUSE)