Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1015816rdb; Sat, 7 Oct 2023 08:13:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHg0qYRb5EFlAZHIzK0GxdPZwYrkwWPOA8bxZN9RvkMg7Kk+2bl7tlpQRXGy5D+72u1FlHL X-Received: by 2002:a17:902:d50c:b0:1c8:75d9:f7dc with SMTP id b12-20020a170902d50c00b001c875d9f7dcmr10514282plg.28.1696691636506; Sat, 07 Oct 2023 08:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696691636; cv=none; d=google.com; s=arc-20160816; b=lgUqKTC6weJUWq4uohn4MBl7AuU5xKSw9rcDzsIpQ0qEkqfdOMjP2b9fSw685pr2m6 qrEs0FT6XEhYVSQRry0HDRrQr868QUOotHsnAMYj0pHQrg7dDGj3P9oxujwwsBJsmmpO zhVwATJLrygE8i+tL3z82AQSiNWm/CWE0CoPiMUa7snRGpnpBrTkS5PbHRCxMYxscmdB p2WIyp4jn0pFhd5alfSduvLETyJK367mcpB1iXKIPaFAI8SIxSUMZHkmSiwJOjwZMqFL vrmSwGMbONUO3apGWGJr88mvISXGne0L3exwFeia/hPj06xVF10TbJ8zpAVu61awHR0E UXNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dgqAnIXXeH9mWDMXjQvN3wvgKO1Ce5NTzFzcD5NvWDo=; fh=f44lhsFpke2STvqcDs+XMjqZ1UoPAyVtpF9DWSiwB3k=; b=HmUt7/HF5zePO1S9WVfvoMTEfZTwRBEwc42sElEcWQBmuyJBsQ951yXtJka6SQT2QY 3xRUoX1AhdZhcUg96dvcHUgw9hbZB2eqMgPDrCsPKBUR7bF05g7OhB30f9s0q7brAZod vSWsi4w0rW4WfCwIP+Oy5avATRSAA0+zuLrodY9FLJ8foxUn65rAm+YiHd7MxxNlNk/q 1fSP/Ja8DrBBKRtvdDVHT7kC+6565rYpazxM6qOJqbmk/IrBORz1aBA7SNf98FHhReCb tMYaLeHKY6K9dAWV2s5mDsE+sgfu2t+IDokyn70VZxYvKiz9UP195Tef9muq2TD1eVH5 Wl6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=dobd+es8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id r18-20020a170902e3d200b001b886d36bf6si2980179ple.226.2023.10.07.08.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 08:13:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=dobd+es8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2FB24803B359; Sat, 7 Oct 2023 08:13:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343999AbjJGPNZ (ORCPT + 99 others); Sat, 7 Oct 2023 11:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229824AbjJGPNY (ORCPT ); Sat, 7 Oct 2023 11:13:24 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83940BC for ; Sat, 7 Oct 2023 08:13:23 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-d81f35511e6so2760431276.0 for ; Sat, 07 Oct 2023 08:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1696691602; x=1697296402; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dgqAnIXXeH9mWDMXjQvN3wvgKO1Ce5NTzFzcD5NvWDo=; b=dobd+es8skvlgpTVlLPxuhz4H6WlTISbS/Igu38zNMv4he7tH/PZUjAK/As65w1yfQ LgQ/ELLJ6a/0qxJhG1wjiOS1ISQYq/XO1m/4yAoZXjANwWGY5dR0nl/iFoV6zN5pvjgv J6m9pNinuTElTumJuPCqVEyCSjMuryfIB2Hqh4pIyTRY9+ZI5+2VbJT2EV4Ub45aO5eD aN516TRaXwRDFKlSyY+00OoJ+xZYtXOQCKhN+ax4R/xKIN1dBSQRnVEh8JXCy4XUi++I TqkTWN2pWS0QcJZZKs45A+bCqwdqXm/9BQR+zyGv21xdur8tXZi1FkdRkCQb4cdChI7+ 9FAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696691602; x=1697296402; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dgqAnIXXeH9mWDMXjQvN3wvgKO1Ce5NTzFzcD5NvWDo=; b=ZwnL8VmsQIbxAOVg6v++t0RjJB9XE50E9cbaHGbJyeihVBr/hP0UHk6byGDsBh8hl2 BvNh550K8GMtRDue21HfYsy5e5ViX/+X3nPCUV2o1LLzNDeEt8k3hlPR+RGqve+g1vn3 vbnbv5U+9sG7E4M+lJR+LoPFsh9YoGtX4TYN/GOdapAhx+F3rI55r+j99MXOLbK8/MLl DF9O3oYphD/mCJCYLfnPc5ndbttFbTN4siQ2702w/kkqUOZBN6RRGK2SrlbNDfL/q/Ce AlP7h16Ub33e4MgBxQGjX4OjYV5ppYXiT0edsAm9BYKKPiMf3Urr05j/+6T+xKSwVCqA TMCA== X-Gm-Message-State: AOJu0YzaFQLTuVCb08YAN62Zc1lDWzJhVoRrQ24P3vy+OMdnIx2tBKl1 GGVdrCtttK8hcmjJan+Ar6XW2+hOBRLIsBN19P3x X-Received: by 2002:a25:1e43:0:b0:d4b:a962:76a3 with SMTP id e64-20020a251e43000000b00d4ba96276a3mr5418892ybe.29.1696691602664; Sat, 07 Oct 2023 08:13:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Paul Moore Date: Sat, 7 Oct 2023 11:13:11 -0400 Message-ID: Subject: Re: audit: io_uring openat triggers audit reference count underflow in worker thread To: Jens Axboe Cc: Dan Clash , "audit@vger.kernel.org" , "io-uring@vger.kernel.org" , "linux-kernel@vger.kernel.org" , brauner@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Sat, 07 Oct 2023 08:13:54 -0700 (PDT) X-Spam-Level: ** On Sat, Oct 7, 2023 at 9:11=E2=80=AFAM Jens Axboe wrote: > On 10/6/23 8:32 PM, Jens Axboe wrote: > > On 10/6/23 2:09 PM, Dan Clash wrote: ... > > I'm not fully aware of what audit is doing with struct filename outside > > of needing it for the audit log. Rather than impose the atomic > > references for everyone, would it be doable to simply dupe the struct > > instead of grabbing the (non-atomic) reference to the existing one? > > > > If not, since there's no over/underflow handling right now, it'd > > certainly be cheaper to use an atomic_t here rather than a full > > refcount. > > After taking a closer look at this, I think the best course of action > would be to make the struct filename refcnt and atomic_t. With audit in > the picture, it's quite possible to have multiple threads manipulating > the filename refcnt at the same time, which is obviously not currently > safe. Thanks Jens. I personally would feel a bit better with the additional safety provided by refount_t, but I agree that there is little chance of an overflow/underflow in this case so the additional refcount_t checking is not likely to be needed here. For the record, this should only be an issue when audit is combined with io_uring, prior to io_uring there wasn't an issue with multiple threads attempting to cleanup the filename objects so we didn't have to worry about racing on filename::refcnt updates. However, for those systems where both audit and io_uring are in use we definitely have a problem and will need the upcoming fix from Dan to ensure the safety of the system. Thanks for spotting this Dan and doing the initial investigation into the problem, if you run into any problems with the patch or need a hand let me know, I'm happy to help. > Dan, would you mind sending that as a patch? Include a link to your > original email: > > Link: https://lore.kernel.org/lkml/MW2PR2101MB1033FFF044A258F84AEAA584F1C= 9A@MW2PR2101MB1033.namprd21.prod.outlook.com/ > > and a Fixes tag as well: > > Fixes: 5bd2182d58e9 ("audit,io_uring,io-wq: add some basic audit support = to io_uring") > > and CC linux-fsdevel@vger.kernel.org and > Christian Brauner as well. I'm going to CC Christian on this email just so he has a heads-up about the problem and knows to expect a patch. -- paul-moore.com