Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp605823lqd; Wed, 24 Apr 2024 11:13:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4IwZ7//7iaImMC+jg9EaEt+bAzK4/0QH90stywu2iQJyB3zYAWTX54uSOHLuiC8zpJ3P9K/pWcWJc/JLUKeJjqZyyoMkhi/YfbwSnuw== X-Google-Smtp-Source: AGHT+IG2KHHn1NGhRRinq+3CSnkhbY4kAEK8HSGf5UgDeiMVKO3g5OpjsHnioBiBzFkS7OjNtfQj X-Received: by 2002:a2e:9010:0:b0:2d7:17e0:ff56 with SMTP id h16-20020a2e9010000000b002d717e0ff56mr2163008ljg.18.1713982430286; Wed, 24 Apr 2024 11:13:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713982430; cv=pass; d=google.com; s=arc-20160816; b=Cscx+cIon49YBaqm4bEPlWH6tL3a8b7Dy+rTYjdigSbSwT2Q7gagzKSqHyW+BEt4Ur 6wNKXH+Fh4OOAvrk9dHIsJKpA6//0TevOUI3X+eXEswAhfFUYC+UuyolHeCe3PvNBTKA jByNAHi8bXw5dQbY1YGw49/YUBpIPuefg/BMfOyNYKhSCGact62kqbKX/AnTOAzLUhy1 I8gc506AK5qsekzIgqd1iPNOTjbLwwVWs2h6JBHcCY+tBnaIQ1VMAoQmykReBqDNq7hP z0WTANN0vJcpCp9Q+392o7QyruSE15I0LYXG1TdL9fIWnLxzpDOMJW0Bz7YiC/2rsJ/4 gLuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=DQDYS5GoGsusvKBlASZ1gEgijb/r2Mz1W1Q6oSnEwMQ=; fh=EZ5La8cAlXER2hQQZ0D+ONO60e1d5UQ2YKqp/cV4+Do=; b=fb9ZMd/nNqMuVo1EtNgwLJRMH3/7oeBCd08S1ul2GmrV1XeRoWsv3qH1lSyNd0Situ MnJDE5KYcqchJxoLNCOJnCgWIv1xZLTzgk0Bp+27CbOgf6z2td1H6CtZopWME6yOBlLp 8xwbo+uEGXDkQ3iC3J2LeGHg81kWfRKq6L5vEYP5fDIJ67voSYq7aelpnHdwgUtGnIMo gCDlpQEvRbHTpBIMGdm6s0wZ9PSyXDqzNE5ZAEFkpoSR/g/AcwfMiJv+QwZymz7H4vps 3A1iIW1LO4Paqkd7vsX99i5gIVTZnclP1KNpMq3ze7w1F3yUGgzHmr3SlvdEfPfi0h6Y DWFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="cJYNSFF/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-157448-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157448-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z15-20020a056402274f00b00571fe8194a1si5367006edd.346.2024.04.24.11.13.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 11:13:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157448-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="cJYNSFF/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-157448-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157448-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C79541F21FC6 for ; Wed, 24 Apr 2024 18:13:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AAF916D9CD; Wed, 24 Apr 2024 18:13:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cJYNSFF/" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DC9716D329; Wed, 24 Apr 2024 18:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713982418; cv=none; b=SinPG01Z0Ebjra2DDAwP3ipOoMCLr+Y5IqekZsYUEHmsBb60AZO2IqH158zqezmrtJAqOc+TyJ/JdobMMVuSyVk4x+/iKALpqjzO57TkwZtDBSQr2otceoejV2pDf/7H7OKYwDlFRkiR2F4yLoPqflOpx8O47JfJz4iQSmr3404= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713982418; c=relaxed/simple; bh=81/fj7NjD+zEcRV5jk9TtHGDgfY372bpY0fjY6dUMzE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JshbuZhOezV6cYTpSHyAm4baop7KOzbpxe55t4Dzd9oyqOtmnjdtQiomxWEo+0HgtvSqoOolJQF4ZOseCtZzzH4whbkKp7c2z0oAOB1suxtEr1OOvt+vtEUERwFkfJAVin3rut6f+xWTaJINiXwUFfkWz0QbXuY2xlYuBYLXIZI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cJYNSFF/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B371BC113CD; Wed, 24 Apr 2024 18:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713982417; bh=81/fj7NjD+zEcRV5jk9TtHGDgfY372bpY0fjY6dUMzE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=cJYNSFF/BQfBxPV0nolpfeWaxorLN5m7KP81JBIPoFpCmnFlQzLnLIyCGw418QS8X xGyREA6XP697XH5DM0tJtxpZBf2DlE/BM/YyQunhzZu6HrfTXpsZZQj5jzL7Y50gso 8cEK5NJfCLmNLFbEE/GR0a3pmBixj7t4LgJpFOnCH+OMgIfEAumIBrA+LU10P7R0R9 SegMtR69zN5sgRn6wU7Ig/XlEe9RFMw1CH+i+ORJv9ZQpkQqSrxQOX+ZTnPXxvFD0q EVQ8O/J3qjb5TmHZYA95Fmznb9zwdsUCzpHcPM1bCQYmfMVVnGYclGuKRGbHS+wacB yf452MPkLMdxA== Message-ID: <8a01c6b2-ca30-448c-8ba8-34720891b461@kernel.org> Date: Wed, 24 Apr 2024 20:13:31 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] nfc: pn533: Fix null-ptr-deref in pn533_recv_frame() To: Yuxuan-Hu , Yuxuan Hu <20373622@buaa.edu.cn>, gregkh@linuxfoundation.org, johan@kernel.org, davem@davemloft.net, u.kleine-koenig@pengutronix.de, Jonathan.Cameron@huawei.com, francesco.dolcini@toradex.com, jirislaby@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, sy2239101@buaa.edu.cn References: From: Krzysztof Kozlowski Content-Language: en-US Autocrypt: addr=krzk@kernel.org; keydata= xsFNBFVDQq4BEAC6KeLOfFsAvFMBsrCrJ2bCalhPv5+KQF2PS2+iwZI8BpRZoV+Bd5kWvN79 cFgcqTTuNHjAvxtUG8pQgGTHAObYs6xeYJtjUH0ZX6ndJ33FJYf5V3yXqqjcZ30FgHzJCFUu JMp7PSyMPzpUXfU12yfcRYVEMQrmplNZssmYhiTeVicuOOypWugZKVLGNm0IweVCaZ/DJDIH gNbpvVwjcKYrx85m9cBVEBUGaQP6AT7qlVCkrf50v8bofSIyVa2xmubbAwwFA1oxoOusjPIE J3iadrwpFvsZjF5uHAKS+7wHLoW9hVzOnLbX6ajk5Hf8Pb1m+VH/E8bPBNNYKkfTtypTDUCj NYcd27tjnXfG+SDs/EXNUAIRefCyvaRG7oRYF3Ec+2RgQDRnmmjCjoQNbFrJvJkFHlPeHaeS BosGY+XWKydnmsfY7SSnjAzLUGAFhLd/XDVpb1Een2XucPpKvt9ORF+48gy12FA5GduRLhQU vK4tU7ojoem/G23PcowM1CwPurC8sAVsQb9KmwTGh7rVz3ks3w/zfGBy3+WmLg++C2Wct6nM Pd8/6CBVjEWqD06/RjI2AnjIq5fSEH/BIfXXfC68nMp9BZoy3So4ZsbOlBmtAPvMYX6U8VwD TNeBxJu5Ex0Izf1NV9CzC3nNaFUYOY8KfN01X5SExAoVTr09ewARAQABzSVLcnp5c3p0b2Yg S296bG93c2tpIDxrcnprQGtlcm5lbC5vcmc+wsGVBBMBCgA/AhsDBgsJCAcDAgYVCAIJCgsE FgIDAQIeAQIXgBYhBJvQfg4MUfjVlne3VBuTQ307QWKbBQJgPO8PBQkUX63hAAoJEBuTQ307 QWKbBn8P+QFxwl7pDsAKR1InemMAmuykCH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= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 24/04/2024 16:00, Yuxuan-Hu wrote: > Hi Krzysztof, > Thanks for your reply. > > On 2024/4/24 13:36, Krzysztof Kozlowski wrote: >> A bit better solution would be to NULL-ify dev->cmd at the beginning of >> pn533_send_async_complete(), because that seems logical. The complete >> callback takes ownership of dev->cmd, so why it performs the assignment >> at the end? >> >> However even above code will keep the race open for short period. >> Probably some locking would solve it or checking for dev->cmd in few >> places with barriers. >> >> Best regards, >> Krzysztof > > I think adding a lock seems to be a better solution, however, acquire a > lock on each access to dev->cmd does not seem to be an appropriate > implementation. > I wonder whether you think it is appropriate to acquire a lock at the > beginning of pn533_recv_frame(), and release it when > pn533_wq_cmd_complete() is finished, thus ensuring that another work > will not start when one pn533_wq_cmd_complete() work is not yet finished. I don't know this driver well enough, but it currently does not have any locking around this so it assumes pn533_recv_frame() cannot start concurrently, before complete callback finishes. This could be solved, if it makes sense. However maybe it would be enough to take: 1. Move contents of dev->cmd to another member in dev (e.g. dev->cmd_in_progress), first checking if that member is empty (then maybe wait? or return -EBUSY?) 2. dev->cmd = NULL 3. queue_work (see also explanation of barriers there) 4. The cmd_complete_work workqueue takes ownership of dev->cmd_in_progress and NULL-ifies it at end of work + barrier. Best regards, Krzysztof