From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 0027E43E9F5 for ; Wed, 27 May 2026 16:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779900324; cv=none; b=WhX6FF02oYOZseaYRiMtypTAkBxWn+9FNoQ6s+zvg2imF9iT/qJ1MuN2J8HZk+et/yRhoVJ+L2DD95XxODSXnt0bekQ148OiRMNs8XfjgtcaMgi+4O8gkjkrJPrJZhHxxu2Bb1P+90DxgXtjWZhd3WX/eK1x576yvCZTtLLKmJ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779900324; c=relaxed/simple; bh=Px96Koc+KE1Llq24SuFqyCNdFUV476yMaxYMtndJ/UA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=enoSVPGQa0+xGZwUBPtnJOxnQ+G1ZkTXcIfTnX1/824oTyhHw7ootvS5YWeuS5aX5n+NfkWs7eODoTMo95O4gWYiqSfeoFQTIMhV8TE15Kfd66iYsL0oaHNlgd9Qh5kVxTX545eILJAYLzq41wqucwmsdbYEo7U7FXf8lUa7SOo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20251104.gappssmtp.com header.i=@kernel-dk.20251104.gappssmtp.com header.b=PGmITyv1; arc=none smtp.client-ip=209.85.210.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20251104.gappssmtp.com header.i=@kernel-dk.20251104.gappssmtp.com header.b="PGmITyv1" Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-7de431da8fbso9889443a34.1 for ; Wed, 27 May 2026 09:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20251104.gappssmtp.com; s=20251104; t=1779900318; x=1780505118; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=dcORsZ+6RO+FQOhB2NjtCmUi3rJoywVrFL/YyMOnoJ8=; b=PGmITyv1gFtGOc+BOGJEcFusxaA/c4h6dxbQwwTmpfDOcZBsxTqSevpcLmm6/xYdqB NP755Jb4bgoPiLU7FQr956I1q4JJoTIl0YFdFHQUN0igabqpvBU5aOxItBS6yBi80Q+Q DU8tpq3GMEMM1QlvywC3ELldx918nVUFJ1TNdWvc54VyLcgiXbb4k4Wm3xSNlWkaHbS/ 16ak2tv9pEvqYtNB61CUod3/Y9xLD8rYqm6FUASZNBjtE1dBVint5GTw/s4f8cFclvO3 UIFk0ODzBNcdesQHJ/ReEEcTAhK5CWW4QQk9QIZVqBkELkBVGzkKlAdXKEvXw5d3Vs7k yhZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779900318; x=1780505118; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dcORsZ+6RO+FQOhB2NjtCmUi3rJoywVrFL/YyMOnoJ8=; b=KZuelm4P4jJY7Whx5NcyqdtbzjkLeiGV7hDrr7IakSM2RyeOgNo43eE82p4oYuJuZD J5KNq6OPp0c8dwOvhO+KpQVAZwlxCz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6830:270f:b0:7dd:e032:3ce5 with SMTP id 46e09a7af769-7e5feed03cemr14415624a34.17.1779900318314; Wed, 27 May 2026 09:45:18 -0700 (PDT) Received: from [192.168.1.102] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e606641114sm11987256a34.21.2026.05.27.09.45.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 May 2026 09:45:17 -0700 (PDT) Message-ID: <07c25a67-54b3-4ecd-bdf1-7ca0cefc8e38@kernel.dk> Date: Wed, 27 May 2026 10:45:16 -0600 Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] scsi: bsg: copy uring_cmd payload to prevent double-fetch from shared SQE To: Caleb Sander Mateos , Rahul Chandelkar Cc: James.Bottomley@hansenpartnership.com, martin.petersen@oracle.com, fujita.tomonori@lab.ntt.co.jp, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, io-uring@vger.kernel.org References: <20260527105931.3950913-1-rc@rexion.ai> <20260527161926.4071110-1-rc@rexion.ai> Content-Language: en-US From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 5/27/26 10:27 AM, Caleb Sander Mateos wrote: > On Wed, May 27, 2026 at 9:19 AM Rahul Chandelkar wrote: >> >> On Wed, May 27, 2026 at 10:06:44AM -0600, Jens Axboe wrote: >>> I don't think this is the right way to fix it, ->sqe should've been >>> stable upfront if this ends up happening. Can you share your poc with >>> me? Your trace has been trimmed down way too much to be useful. >> >> Agreed that a core-level copy before the inline callback would be the >> right fix and would eliminate the entire class for every uring_cmd >> driver. The per-driver copy was meant as a minimal backportable fix >> for the immediate scsi_bsg path. >> >> PoC and full trace below. >> >> --- PoC (poc_bsg_toctou.c) --- >> >> Build: gcc -O2 -pthread -static -o poc poc_bsg_toctou.c >> Usage: ./poc /dev/bsg/X >> Needs: 2+ CPUs, io_uring, /dev/bsg/* access >> >> The racer thread flips request_len between 16 (passes the <=32 bounds >> check) and 128 (used by copy_from_user, overflows scmd->cmnd[32]). >> The overflow payload plants 0xdead000000001000 at the sense_buffer >> pointer offset (+84 from cmnd[0]). When scsi_queue_rq() does >> memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE) it faults on the >> corrupted pointer. > > Then the fix is to use READ_ONCE() to access the SQE fields, right? > Copying the entire SQE seems like unnecessary overhead. See > nvme_uring_cmd_io() for prior art. That is indeed the correct fix. -- Jens Axboe