Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 E652F3385A3 for ; Thu, 23 Oct 2025 15:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761233647; cv=none; b=RRjksiH+Mu1k22kBKdBgLci01MK/BwNBgIS6ug4OIHdP0XXmQIf4/rHANa0+8QG5jkObIhxl1Kanxx9fSnaiZsHMmJxVQ17RV35vuihD84texCZsVkQ3rrv23ribBVGDYl3GhPxtzB+6fcAMDdgXZby14THDbAwDjWImP08Ge6Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761233647; c=relaxed/simple; bh=OWkNB3KsQoqRzn4yt3JHu+sASKlGnlK4DEMVdIzWjQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mWXEfh1lq+ErlU8k6qOoC5ru0fv1DQTd3LJ8JBOV9FLoWCb+Sk4UkCLbjPJxmcYoQSlQUSjDim59t3SkcyECOEKnRNDsHCfcv8m+7Qwz3IECSm31NqRg+5dBaS9IMpHWL4SDfJzEg72TcO7sHkcjoyHXFWdYT45SE4V3db28veQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BkclO6Z5; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BkclO6Z5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761233645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tEXpTFwEBc71QEQ792eXKvHhn2jRtsPzJ0arHVJOcDo=; b=BkclO6Z5fOPbZdRwuH1yki5oivJ/t4K4gZkndLOvS5/zDtya/KxE17mDWO/9IG1j3brNEM n3YmerCQfuSkwRePC8URPtNBksqslVQlXIHu3Ou/cm8o6pbK30qmudoXutoApK4Mvgjk/J sBSdOV//+z9I4xnna9LoissCcp5lclw= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-5t1tKzRBOtGGF-g31aenew-1; Thu, 23 Oct 2025 11:34:01 -0400 X-MC-Unique: 5t1tKzRBOtGGF-g31aenew-1 X-Mimecast-MFC-AGG-ID: 5t1tKzRBOtGGF-g31aenew_1761233640 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6D1C1800378; Thu, 23 Oct 2025 15:34:00 +0000 (UTC) Received: from localhost (unknown [10.72.120.30]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9941E30002D7; Thu, 23 Oct 2025 15:33:59 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Uday Shankar , Caleb Sander Mateos , Ming Lei Subject: [PATCH V2 17/25] selftests: ublk: fix user_data truncation for tgt_data >= 256 Date: Thu, 23 Oct 2025 23:32:22 +0800 Message-ID: <20251023153234.2548062-18-ming.lei@redhat.com> In-Reply-To: <20251023153234.2548062-1-ming.lei@redhat.com> References: <20251023153234.2548062-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 The build_user_data() function packs multiple fields into a __u64 value using bit shifts. Without explicit __u64 casts before shifting, the shift operations are performed on 32-bit unsigned integers before being promoted to 64-bit, causing data loss. Specifically, when tgt_data >= 256, the expression (tgt_data << 24) shifts on a 32-bit value, truncating the upper 8 bits before promotion to __u64. Since tgt_data can be up to 16 bits (assertion allows up to 65535), values >= 256 would have their high byte lost. Add explicit __u64 casts to both op and tgt_data before shifting to ensure the shift operations happen in 64-bit space, preserving all bits of the input values. user_data_to_tgt_data() is only used by stripe.c, in which the max supported member disks are 4, so won't trigger this issue. Signed-off-by: Ming Lei --- tools/testing/selftests/ublk/kublk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/ublk/kublk.h b/tools/testing/selftests/ublk/kublk.h index 5e55484fb0aa..87bed2ed6521 100644 --- a/tools/testing/selftests/ublk/kublk.h +++ b/tools/testing/selftests/ublk/kublk.h @@ -223,7 +223,7 @@ static inline __u64 build_user_data(unsigned tag, unsigned op, _Static_assert(UBLK_MAX_QUEUES_SHIFT <= 7); assert(!(tag >> 16) && !(op >> 8) && !(tgt_data >> 16) && !(q_id >> 7)); - return tag | (op << 16) | (tgt_data << 24) | + return tag | ((__u64)op << 16) | ((__u64)tgt_data << 24) | (__u64)q_id << 56 | (__u64)is_target_io << 63; } -- 2.47.0