From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (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 5BEE61FECBA for ; Thu, 5 Feb 2026 13:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770298946; cv=none; b=fDG0XA8lgkdZ0VltdoABnte3X1P9q0AJfLrhrMmAmyIa61X5QHLN2TboqmRWVTVw9k5fz5AnQ8xD/h1+v6YBTSqDsVflMFn+EkB/W0yCdNB1Dd3ToU94E9hQ8oFcuFxN9PeYj2P81AycgnNW4d0B1D1tO8IRWftKIQ1NVcfnerg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770298946; c=relaxed/simple; bh=xIx81HrAdepNOt09t94202ep8WkrBqZ8CIGLzoa0bq0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=uDEiSOXuia1X0HGkdcArhIetz0Cv7goFlJBtdYWzst6oVW6MDh52aX3WWw2Haq/SxLbHgoJ2cQY7lqDbehsRSbPjmTQto6XAMeBblGXpe50PZzJ2p600ZejY6E5nemJw4TMaMG5Kad2CLe0O4gCjQcFkuhtx9ls/n20au6uRnl4= 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.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=ILwBHZvo; arc=none smtp.client-ip=209.85.160.50 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.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="ILwBHZvo" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-40970f97638so612733fac.3 for ; Thu, 05 Feb 2026 05:42:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1770298944; x=1770903744; 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=jZeINKNQdVEKrTfLswXkJRH1jAKC3+hNj3Wq8FHgwG8=; b=ILwBHZvoer7VNIIlB1ubVJOnFAUPRBR6+XvQ/H6fZ4wJqqJC0Bv7u2UmrhYLJYqXsO 1VbLLYkPD74kWmXxkQdNOr+rpDteEctLX21j+H7Hy1smBZP0IAJFWOkp7j2Wn5VsA+k5 chR+harbe7X5yuB1WIb8N9bWPwMYldWbYRtF+BK0uMhwXj6C7lx4WHv4ni++rpENlJwH V3LASsoqFiBi/yZrUxaKoTEKOy3gi1MChcstSVeQPkFB+cCa7sPUi2SxSSyQQ1yFj4Mo WuArzWF/2la4oDnt4iKY5UVmg5mO7o6kR/6c3ZoQhO7zYP/WkvHlKw19TN+hfdDpZsYh gAGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770298944; x=1770903744; 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=jZeINKNQdVEKrTfLswXkJRH1jAKC3+hNj3Wq8FHgwG8=; b=P8WSxcz7dqeMoK4sJGrjZHELlXhAW9+6HpO/rjClwuAHGLVbM4ph7evU0xG+MRjFu/ yQWQuq2EYVHLu3GqErf9nXDRmftECTTD+BPx+3QhEArR7yOJzs35tW7e/6RXC6v+mL3R 5dtExaQ032xImJiVjr7DeIZH6s4Mhs6OzVAGmLyGvAB/R6k5WzG22RiKUYw2KW7lBZWk MacisTlkap/yXo+aUYU/nHgTgAieaEodQBc5TnO2jxP96YBoiazNV1ETsECuIjdwgLhs aUQMez7gWj0mE85xlG0bYZDZ77F4/pRWm0G44NJ3+icg5emQxZf8w8dgD4KpBo/p4lWI RwkA== X-Forwarded-Encrypted: i=1; AJvYcCV2hWxR2tWPIhBd5zNs0EsMSilF0Yd7/b0fhGDSqufnV92RTP8qqk334hnHyDnFXtUXNTS0g5SoTYNjy5o=@vger.kernel.org X-Gm-Message-State: AOJu0YxXnkOVev7IRv21E+VWNfnu80nn3eooIneOgSxuEWrhlFHIti4P EjbA2tdnllh/mLWsryUQ+Om2hLmprhXmHnlsW3cUnZrgCK9O0UVvSk3YEwlgyFk2B1s= X-Gm-Gg: AZuq6aKRHfrIysuNy7hJeUnMZNZ3906Su4ZXdvH0UTaohXNWL4LspQpAbzbekXWQ+74 TXhSp/6KbX1i5XyZNvVLwmY/9SFpoty8sqkcZ7JNjtWoYFLnlIs6YYY+LQk9koclhKdfITseRsR a6/SKYHTDEfwjiARJJRVX7SC+i2U6C3fMdnT0Rr2KdM8N1V7JGy/fq9epTk6cpNKrJAHwVXxD6/ LXbai5AkzZaLF/tNKF/S3K0bJzozpsSJ6OMTuBEJrRp33eoqjR1jWPOSInPYUVhEqcqo1Opdbzl Wx8q3oSM6zH3pAiuhWznFTa8CnjRw4OuttjkOUQt6HZ3TkA8nvNv3kpCRIKOTrAjedu44QTEeA3 Ch4buC97MqWI8+rQQFUYC3kmOoqwpIq6xCh6Lkc/JcRJtPGythe/k3JYmY6fIiDsyx2JAAngTS1 0sN2YkI1jjDbbjPI3TSJc9gkBCAPhiXDdadhjGOYzhE8Y56nzUYPKAetC4QGXrBncXSJu85g== X-Received: by 2002:a05:6871:4b0e:b0:3e8:8e56:6717 with SMTP id 586e51a60fabf-40a540fb025mr3618579fac.55.1770298944180; Thu, 05 Feb 2026 05:42:24 -0800 (PST) Received: from [192.168.1.150] ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-40a541e222dsm3942638fac.8.2026.02.05.05.42.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Feb 2026 05:42:23 -0800 (PST) Message-ID: Date: Thu, 5 Feb 2026 06:42:22 -0700 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] bsg: initialize request and reply payloads in bsg_prepare_job To: jonghwi.rha@samsung.com Cc: "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "hch@lst.de" , =?UTF-8?B?6rmA7KCV7YOc?= , =?UTF-8?B?7KCV7Zic7Jew?= References: <8c7399bf-76b3-4902-b257-b85c95543f6f@kernel.dk> <20260202120425epcms2p481d034d2a8fc522819673f0bcd59cefd@epcms2p4> <20260205053219epcms2p20a936a2fa681d19d3386fd480c283447@epcms2p2> Content-Language: en-US From: Jens Axboe In-Reply-To: <20260205053219epcms2p20a936a2fa681d19d3386fd480c283447@epcms2p2> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/4/26 10:32 PM, ??? wrote: > bsg: initialize request and reply payloads in bsg_prepare_job > > struct bsg_job payloads contain fields that are only populated by > certain commands, such as sg_list pointers. > > Because struct bsg_job is allocated with kmalloc(), memory may be > reused across requests. If a command does not populate all payload > fields, stale state from a previous job may remain and later be > misinterpreted during cleanup, potentially leading to use-after-free > or double-free issues. > > Initialize both request and reply payloads at the beginning of job > preparation to ensure a clean state for all commands. > > Signed-off-by: Jonghwi Rha > > diff --git a/block/bsg-lib.c b/block/bsg-lib.c > index 32da4a4429ce..0fbf8e311c03 100644 > --- a/block/bsg-lib.c > +++ b/block/bsg-lib.c > @@ -234,6 +234,12 @@ static bool bsg_prepare_job(struct device *dev, struct request *req) > struct bsg_job *job = blk_mq_rq_to_pdu(req); > int ret; > > + /* Clear stale SG state since bsg_job is reused as a request PDU */ > + job->request_payload.sg_list = NULL; > + job->request_payload.sg_cnt = 0; > + job->reply_payload.sg_list = NULL; > + job->reply_payload.sg_cnt = 0; > + > job->timeout = req->timeout; > > if (req->bio) { The patch is white-space damaged, tabs are spaces. But I can fix that up. Do we just want to do a memset(job, 0, sizeof(*job)) here to avoid any oddities like this in the future? -- Jens Axboe