From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00260335BDB for ; Fri, 24 Apr 2026 12:38:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777034289; cv=none; b=TqsSg0eAvhRSxFrFkbC6651MZEtxqS+X3ckxmtEE8OFsMdGQTp43uYyNzpQqygg8i+6shxDdv1++4Xl9lXHwBVuv/EbXmTUDVO/Dl7D7vkvkEbKdTtCSpULMj8oOfF0hZxdKG0+IRU75KoYpO9vhYL/A3ZheyiSskzX7JIT2hSU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777034289; c=relaxed/simple; bh=eph4YoIDCHwwmTEvupL5zZSWeDF9pX3nLS3ud8I6gtY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GAKnt04HmSd3k5R7NWCCt0uCbKXB6+ZXwI2+iNnZbs6rbXhkiFBQew2Sa+nmHIvEPFb7pz6ESw+ABDDpYgpXomOTK4DSJ8wepoTUG9jUde+mJhl6bj4Ugt+VdMmhG5AFkk2v5F7OMWr9x9sA6m+x4t9eZc6Feh5xsbtSjlT1oHs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EPShNyjf; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EPShNyjf" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-82f8b60e54dso5216463b3a.2 for ; Fri, 24 Apr 2026 05:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777034286; x=1777639086; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3sp1w0jMCzr8SFytSaJnbUVIcN3ZGD9PMN3uxgImAUE=; b=EPShNyjfJbvK7SX5NFmS60ntF1qGVrMr3agTO/7fHS2MLpTA2TdyWlGkZV4ix4jhRo trtIpWpl4eXbgRecIeZjtUcxhDtt3rOfPnuiUJxxYtriW0qj330LMgpsU7e2ACYBsGpT cG06RCEyIzSjv+Nu3tZWQFC0Rgu06l9e7i6A6v4WejGVuZqnrDY5WsiIxb13evf8R8U4 54l/ZOE/P+uf2BJVhPPXHTE87599x2oFwUy2YDUeQWyioAkvcUAkCUBuy/6NYiTpO9cF ksiV5UTUqDgJ4uYcxl3SzC/u75HxPKdF9QZ4K0n4hqQAGUznR9LDlR5tHcCo6z2uN10N IYxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777034286; x=1777639086; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3sp1w0jMCzr8SFytSaJnbUVIcN3ZGD9PMN3uxgImAUE=; b=W+ffdJyX06zdrvm2pZF5ca8KVT8+/w1PjmoF+ImtpFFhFVWsFfvP3vfuy4DmuWQQA9 m7NRjJ3rX52AZZi3JShOjs3SDm7cXzP6j0nJju44S41EYhLIwpbAHF2yIZ0xzp7SCT92 zTUgZWdErGeXQ408nDoQF6J7JoKjEFbIfA24s0Ds8zOoWcNqGq3c3kF36PhquscCrOHl ZEjAnVj/kHDbTKeNR/NZEIZRxuCuMzbAJt0e+/fusixRnPl1jCkIC1kRTUwZ2/9qmTrU 9D0DTSNpUpRjmKFlLFeXBPtD2em8rxnX5C0pWSnqPAyWTBl44URKRziKHT0DltZCOvo3 1iBQ== X-Forwarded-Encrypted: i=1; AFNElJ9i0i9Jt5U4a+Ou0svO+xlhG/CpQcEtu/rX/GBcDtkMP3DxsnflQC2zbxFHzOwU9CSde5CRvPb5iLJPmwQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7xwzRNPZLBbt+1DEiwlKTsFGEuJT/Cng9CLajLsExto6tfv/1 gOB8t5bdIm9gUGNZdnV3nQvCycifb40m0QS0+TDVB4Oe6GjKpaeVY8xP X-Gm-Gg: AeBDietd4WAMJwZus78pdSIlyGpoYjpI+s1/JvP4NNRlD/QqRNlDEj79TQeZS9e0ItZ t90PS6pGSts8uYrH2W/gmvnyMBHu/VBV+XnNEE6Fi5EH6pK8WI/k8Ca03Bc5HZqXZqTs7or4nyW Or43BCZFm+5+2j0tDvzfQd8a6r4h/c1yd+xgD+Ra8Ax4+91Q8eXhHFGAc/rqrWcZZHdb8GvfoHm efpqtPKMOxkT0Lzevt+hpodo8FGvCjeyWkT6bNJ1DuMK1u51rJ88svGhi+UUTAGGYirtJnij31B rH7Twy4Z+Hx5z7HjiMvqU6Jk/on79aq5m74H/s19r0AA8AazDf/py66bVtpw5TyeEye+I3vSgCz /B67okzfqSBDWe2iNEX2j5T9928NqVJtCFQ1hYeRYUsKOlojvGvyUvaWNslSo5BckhCaG7GPtty BAJNKxuBmlMlpl2e+5sYK0/zhoCUZNGDWh2l2wRHgzaHdIDrVYmsGYOTl6NQLt6GuCg0P7niAp X-Received: by 2002:a05:6a00:2e15:b0:82f:250b:9f16 with SMTP id d2e1a72fcca58-82f8c90261fmr35624587b3a.28.1777034286205; Fri, 24 Apr 2026 05:38:06 -0700 (PDT) Received: from uroburos.. ([2405:9800:b651:afcb:b017:879f:ce5b:d91]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ec04448sm28131075b3a.55.2026.04.24.05.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 05:38:05 -0700 (PDT) From: Adam Crosser To: Dave Penkler , Greg Kroah-Hartman Cc: Andreas Kleinbichler , Luke Yang , Al Viro , Adam Crosser , linux-kernel@vger.kernel.org, Ruikai Peng Subject: [PATCH] gpib: fix double decrement of descriptor_busy in command_ioctl() Date: Fri, 24 Apr 2026 19:37:47 +0700 Message-ID: <20260424123750.855863-1-adam.r.crosser@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Adam Crosser commit d1857f8296dc ("gpib: fix use-after-free in IO ioctl handlers") introduced a descriptor_busy reference counter to pin struct gpib_descriptor across IO ioctl operations. In command_ioctl(), the error path inside the loop decrements descriptor_busy and breaks, but execution then falls through to the unconditional decrement after the loop, underflowing the counter to -1. This re-enables the use-after-free that the original fix was meant to prevent: a concurrent close_dev_ioctl() sees descriptor_busy == 0 on an actively-used descriptor and frees it. Remove the early decrement from the error path. The post-loop decrement already handles all exit paths, matching the correct pattern used in read_ioctl() and write_ioctl(). Fixes: d1857f8296dc ("gpib: fix use-after-free in IO ioctl handlers") Reported-by: Ruikai Peng Signed-off-by: Adam Crosser --- drivers/gpib/common/gpib_os.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/gpib/common/gpib_os.c b/drivers/gpib/common/gpib_os.c index 97c98f0..2b4ec6a 100644 --- a/drivers/gpib/common/gpib_os.c +++ b/drivers/gpib/common/gpib_os.c @@ -1018,7 +1018,6 @@ static int command_ioctl(struct gpib_file_private *file_priv, userbuf += bytes_written; if (retval < 0) { atomic_set(&desc->io_in_progress, 0); - atomic_dec(&desc->descriptor_busy); wake_up_interruptible(&board->wait); break; -- 2.39.5 (Apple Git-154)