Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1129963rdh; Fri, 27 Oct 2023 05:47:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuVRRwlIrYkqWSU91981OxqD9Mk8dUw190qqEY1MNZxMzfSZQeJ1jEo0tNDO3j9BufRmbs X-Received: by 2002:a54:4090:0:b0:3a3:e638:78d2 with SMTP id i16-20020a544090000000b003a3e63878d2mr2489698oii.12.1698410852428; Fri, 27 Oct 2023 05:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698410852; cv=none; d=google.com; s=arc-20160816; b=cQTVWM+z/U6XVCbAD0Y04n7NDiECWVVlA+8OQajjYN9ZhV1WdZa3cidIRrZ7Qj7ItH uaWefKbJp1kw2pH4MPdUhdNrd9qfMQwbwLKCavo5v+jkjozXKzwPub5Bn6aMVdHVh7PB mR0S7tfLOi5osEHuSMpkO6XU2R5+Zel+UNCvSXkFAnFESP+faMxGSjDOqCTAxPYsfo/D Rb0R95uIS2ESOzTaO7K7ce8bZZXGuK7+wX4IjhePaLukGETeJDSDaP1Gts1E0ydIWKB8 2rVE7YtltC/+aCEMqBT4pAQo6PRqV2XBxIVPJJtzZlFUF5c8REqiAl7I1nDbislIr1Xs fXvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=H+PtxNveSYF0PZxJqK9VGUgEq1qARfXij9oa/0ZSPmk=; fh=KEa04yd30XKBA20D0SGcPhQTsgRadIdOfiT26T5+Vpc=; b=ZrPfDe6HTZ97a5aYfoREVVS9DSR/07obkbV1VRWnuiA4F05CIotYmIoOTtPLKmNUP2 UX/8AI0/oaAz9Ssz+00Lamd45Yx++7WelvR1L+9zs1nBDZ8eN8NBt+d1IF4u3VXdylF9 uccWb8bs2FplmfTPf6V355qyXVLm7dkOSGBtxFb3xsksihFmMK0e8QvOCzn8c/JCOoK+ 0HDws50VAiCgpbHuOnOE1QcwzJ8Bh4vzNmcayXHfNQD8NuUO3twYp0zEBCs+vdSE3mez oPBUOnffDtPE25m+G4VR58YdJppD2aiXjQ+IPeJo39Q0a4LluAsALoehxFjpuznYBW65 6zag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=gkG884h1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id z6-20020a258686000000b00d9ca7235c2dsi2684483ybk.499.2023.10.27.05.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 05:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=gkG884h1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id EAA8E801BAF5; Fri, 27 Oct 2023 05:46:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231622AbjJ0MqH (ORCPT + 99 others); Fri, 27 Oct 2023 08:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231461AbjJ0MqD (ORCPT ); Fri, 27 Oct 2023 08:46:03 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:242:246e::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 940E81B9 for ; Fri, 27 Oct 2023 05:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=MIME-Version:Content-Transfer-Encoding: Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=H+PtxNveSYF0PZxJqK9VGUgEq1qARfXij9oa/0ZSPmk=; t=1698410761; x=1699620361; b=gkG884h1jaZryTMpfQBZ5SVVfNkP5DTYqO/lHqq/haKv+s/ kXmCf0Yn5ScvTGJ4+rBRxzJ3hszbIpWiTSiH3o8TCMDSgZv2FFJapEmFdWd+1YMgmxBG4DSWIbfxX iGeEZXgcECN4UZlaPHdthTdc3u1dJWtboeEI3KZrOiTqHfSVHkgDR7uEGV9gmqVOIica+R+xY/pnh pdl+J1YnARscE2Ql/iqtFPh9zu5R0EDEuEwogqEfQYom/gNR2+n3lXgQNhxlP0AKW8Uf3y97WyIRu CBclun++AWS8cxaFZhznoEXkKF8sKnNs1IGJ7oi6g9odSP08y0ZQnqkxml1hRsUg==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97-RC1) (envelope-from ) id 1qwMDu-00000004jWi-0We8; Fri, 27 Oct 2023 14:45:58 +0200 Message-ID: <22ab53d1ae36d4925732e6e1dc989dc75af126da.camel@sipsolutions.net> Subject: Re: [PATCH] Devcoredump: fix use-after-free issue when releasing devcd device From: Johannes Berg To: Greg KH , Yu Wang Cc: rafael@kernel.org, linux-kernel@vger.kernel.org, kernel@quicinc.com Date: Fri, 27 Oct 2023 14:45:57 +0200 In-Reply-To: <2023102730-twins-thieving-d04e@gregkh> References: <20231027055521.2679-1-quic_yyuwang@quicinc.com> <2023102730-twins-thieving-d04e@gregkh> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-malware-bazaar: not-scanned X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 27 Oct 2023 05:46:23 -0700 (PDT) On Fri, 2023-10-27 at 13:11 +0200, Greg KH wrote: > >=20 > > static void my_coredump() > > { > > struct my_coredump_state dump_state; > > struct device *new_device =3D > > kzalloc(sizeof(*new_device), GFP_KERNEL); > >=20 > > ... > > new_device->release =3D my_dev_release; > > device_initialize(new_device); > > ... > > device_add(new_device); > > ... > > init_completion(&dump_state.dump_done); > > dev_coredumpm(new_device, NULL, &dump_state, datalen, GFP_KERNE= L, > > my_coredump_read, my_coredump_free); > > wait_for_completion(&dump_state.dump_done); > > device_del(new_device); > > put_device(new_device); > > } >=20 > Is there any in-kernel user like this? If so, why not fix them up to > not do this? >=20 Maybe this is only a simplified scenario and whenever you remove a device when a coredump is still pending this can happen? Actually, no, wait, what is this doing??? Why is there a completion and all that stuff there? You shouldn't really care about the dump once you have created it, and not pass NULL for the struct module pointer either?! johannes