Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp689302rwj; Fri, 23 Dec 2022 06:58:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXuiO5tcCZqCQ3l3X+AYSe7p80HdpHbDEotGNADaeWHl33JcrV80ioW0mcDP0N73q4Mdxkk5 X-Received: by 2002:a17:906:99c7:b0:7b5:860d:7039 with SMTP id s7-20020a17090699c700b007b5860d7039mr8789329ejn.10.1671807536299; Fri, 23 Dec 2022 06:58:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671807536; cv=none; d=google.com; s=arc-20160816; b=KkYqn+U8B8pH5nc5bRmVXx0A3fIs1pYDKUAxS7uOXAjfSRYVYUpC9jf/7Sb2D0q/ls e6umuT+R8O6cfBtRA7i56BIOeRTGgXok+GYHixyl1HaPj9U5sns1boBgf/SnJd+T9xWq G7L3kzgdIyJUeK9ZqI+Kwtpq+m5S1rHZq7aR9TiqdBpacuIQ5RBEIFxJ/o64lnHqS26T yFk/y4M66XSAH1o2fqbCXvJf4HNq61zISbfBBkUP2xYII7Vp5kukGfL1BMIJ7J7JIciZ Qdjou8sBOYiDW0i+COQJ9uWtqOY4TVETmOztEXBJgYif71GmtrXOYWg71KV20ImZGubf cuKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4TWjYMCVD++EuCYPhYhJlYHm4Sr+ILgIf3GmAq16w/4=; b=MBsBmO9ovqH6qos+fnYkKkeZdRqxdGv0c2zYNVF8K1oZMAb8uN/fgGPaj8YLLAxbSF J+kLf3apncPefP9ecoU2ubUGcEJ7h0L6KFhxefogP3neUU0W5f3nd+h0WVzjuvgfABb+ EGJ/y4Vb1fggO25hhAQZs/Kzq/1FR6p84yMWkq8EeXMfK55nM7VnlC436wI1E5nIpLVa qVyGhhtbZUkYVYuUcB8n0kUpjXI1TMyXKnRCSaUpPtd5oDR4k3LI9ClfPdEkst2FM/Y3 TMca/F9mAkgzCJN1X0ePVTqb+xg1ZlgvtFLpb/woMrRFhk2HsIAfwJiSnG4qVWoTiegq 9fww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mon3qRVu; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xj4-20020a170906db0400b007c0b777d1c0si2946068ejb.737.2022.12.23.06.58.41; Fri, 23 Dec 2022 06:58:56 -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=@intel.com header.s=Intel header.b=Mon3qRVu; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236311AbiLWOle (ORCPT + 65 others); Fri, 23 Dec 2022 09:41:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbiLWOld (ORCPT ); Fri, 23 Dec 2022 09:41:33 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 253EAB85D; Fri, 23 Dec 2022 06:41:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671806492; x=1703342492; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0+6p+VS1oE94n8QNDeI1T8hMST+L9ogs9AORZAYfFCo=; b=Mon3qRVuQo8EKaLJPfUgIGWwRgt9OIzhoUKdJUKbJJpiO2QbXw7MHv5M egtdJB/yBxiBEpP0LMiadYSaUgrBanZsL3c1dU8n4v3ilZYfBO7TcHL5B 4SIcUYxrdxOwLSnIBJMhKdHCy1oKF1EgZzXMSNcNaRgNBI1khheWpzpqo 0k3BhUVFTd1uunG7NckIHrOagLKNBJyD7TEYWOW9Ut43qsg1T5o3wJkgQ wbRuVMYk2lNkUHhtjXNINCYWlSZBfviU7CPLAY9BOwvMHIFcumGzyJ7if 22wybmTlHKxcEF6WPljBkXf9nN/ul9J0CRzZop/ZhOk/p80GkIPsMvhyk g==; X-IronPort-AV: E=McAfee;i="6500,9779,10570"; a="406579808" X-IronPort-AV: E=Sophos;i="5.96,268,1665471600"; d="scan'208";a="406579808" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2022 06:41:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10570"; a="720664512" X-IronPort-AV: E=Sophos;i="5.96,268,1665471600"; d="scan'208";a="720664512" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga004.fm.intel.com with ESMTP; 23 Dec 2022 06:41:29 -0800 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 2BNEfRpL017707; Fri, 23 Dec 2022 14:41:27 GMT From: Alexander Lobakin To: Dan Carpenter Cc: Alexander Lobakin , Prashanth K , David Laight , "'Greg Kroah-Hartman'" , "Gustavo A . R . Silva" , Shuah Khan , John Keeping , Pratham Pratap , Vincent Pelletier , Udipto Goswami , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , stable@vger.kernel.org Subject: Re: usb: f_fs: Fix CFI failure in ki_complete Date: Fri, 23 Dec 2022 15:41:19 +0100 Message-Id: <20221223144119.1840796-1-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: <1670851464-8106-1-git-send-email-quic_prashk@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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: Dan Carpenter Date: Fri, 23 Dec 2022 12:04:18 +0300 > On Thu, Dec 22, 2022 at 06:21:03PM +0530, Prashanth K wrote: > > > > > > On 14-12-22 11:05 pm, David Laight wrote: > > > From: Greg Kroah-Hartman > > > > Sent: 12 December 2022 13:35 > > > > > > > > On Mon, Dec 12, 2022 at 06:54:24PM +0530, Prashanth K wrote: > > > > > Function pointer ki_complete() expects 'long' as its second > > > > > argument, but we pass integer from ffs_user_copy_worker. This > > > > > might cause a CFI failure, as ki_complete is an indirect call > > > > > with mismatched prototype. Fix this by typecasting the second > > > > > argument to long. > > > > > > > > "might"? Does it or not? If it does, why hasn't this been reported > > > > before? > > > > > > Does the cast even help at all. > > Actually I also have these same questions > > - why we haven't seen any instances other than this one? > > - why its not seen on other indirect function calls? > > > > Here is the the call stack of the failure that we got. > > > > [ 323.288681][ T7] Kernel panic - not syncing: CFI failure (target: > > 0xffffffe5fc811f98) > > [ 323.288710][ T7] CPU: 6 PID: 7 Comm: kworker/u16:0 Tainted: G S W > > OE 5.15.41-android13-8-g5ffc5644bd20 #1 > > [ 323.288730][ T7] Workqueue: adb ffs_user_copy_worker.cfi_jt > > [ 323.288752][ T7] Call trace: > > [ 323.288755][ T7] dump_backtrace.cfi_jt+0x0/0x8 > > [ 323.288772][ T7] dump_stack_lvl+0x80/0xb8 > > [ 323.288785][ T7] panic+0x180/0x444 > > [ 323.288797][ T7] find_check_fn+0x0/0x218 > > [ 323.288810][ T7] ffs_user_copy_worker+0x1dc/0x204 > > [ 323.288822][ T7] kretprobe_trampoline.cfi_jt+0x0/0x8 > > [ 323.288837][ T7] worker_thread+0x3ec/0x920 > > [ 323.288850][ T7] kthread+0x168/0x1dc > > [ 323.288859][ T7] ret_from_fork+0x10/0x20 > > [ 323.288866][ T7] SMP: stopping secondary CPUs > > > > And from address to line translation, we got know the issue is from > > ffs_user_copy_worker+0x1dc/0x204 > > || > > io_data->kiocb->ki_complete(io_data->kiocb, ret); > > > > And "find_check_fn" was getting invoked from ki_complete. Only thing that I > > found suspicious about ki_complete() is its argument types. That's why I > > pushed this patch here, so that we can discuss this out here. > > I think the problem is more likely whatever ->ki_complete() points to > but I have no idea what that is on your system. You're using an Android > kernel so it could be something out of tree as well... Correct, CFI would *never* trigger a failure due to passing int as long. It triggers only on prototype-implementation mismatches. The author should go and check carefully whether there are any places where some implementation differs and then ::ki_complete() gets passed with a function typecast. Also, there can be places where a proto has an argument as enum and an implementation has it as int. Compilers don't warn on such mismatches, CFI does. The latest LLVM Git snapshot with `-Wcast-function-type-strict` enabled could help hunt such. > > regards, > dan carpenter Thanks, Olek