From nobody Tue Dec 2 01:06:27 2025 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 484F12773D9 for ; Sat, 22 Nov 2025 17:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763833054; cv=none; b=fHtcGjOwBo/il0zp4KVmDxsmIlmbLXxKYs1Ua/UVhxO7e6Gd2lU7xQzc7h1149b8EtB9xRbTNryIodvS4TxbLhkZjkPoObpCxR1cVF7OkM1Egde4uTgZLGTQMBizogWTPFfGjttFJA/E9tGqrjmUjHjx3PoLx46rPhKMmyYlGnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763833054; c=relaxed/simple; bh=jgSpPfKX7nKuDlbS1ie3b78ZMi4lnqU28xD8BnkyxRc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NZQoqdHyta0CUkKUC9UJrhx6A6RtphgHARkmUlLIzXolIDhOz+OcCpFP2DEI6iSuCr+qdhXztajbDZUAKmAiNmh/wzPGsJTefvsMQMlpRAg+DjOkzpPSyVfxnt8sF5l0yT5ffU6BuyNeF8s60yfBloyrGm09QAhPgVStggy1DDA= 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=GnrAa+h4; arc=none smtp.client-ip=209.85.221.47 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="GnrAa+h4" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-429ce7e79f8so1739050f8f.0 for ; Sat, 22 Nov 2025 09:37:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763833051; x=1764437851; 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=zNcsW5vBnLmxdCKt7kb43zPkWdZHd7JLYgIeVgNn+Ng=; b=GnrAa+h4VoONSlN3XqKtSFagoITSpngz1hHBNfl58ezjc04F54QtizrFnVa7lX4lLj MJsHBMXWFI80lOKbEzw4bW7rE5B61GkipO1i8Ctp4meR2leKgX1fdnapz1p9cJy3EGrX zrZAoI9zXvPXGOnY/0KaD1Tcdlg36dV113fPRLRY4joytGoD3vKJibYnEei33/LV0pqp isRO/x1179k21aSTxWFQ3llhJEuXJwf5EM6NOmkSIOKCZ2Lr3lK+1daK4GHO4BznlcgB ehIRzVVOUeGz9KCiOmf5/n92HZ46iKvzLbkEqByhNi36jnmuGO09KTKkIZ/Xnb2Tl6ir W1Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763833051; x=1764437851; 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=zNcsW5vBnLmxdCKt7kb43zPkWdZHd7JLYgIeVgNn+Ng=; b=d8LEyNcJv4GLnjJ8dz7qQnymykFNCJl5+jIGgpGEjGSYaMf5vkRuCMOcT7/d17xr3f I3nlAgLUc5xlNGjIHI5Zm/CNb8omPgSQUWsUS/SmuBLUqXO7rTbaR9m7znX6nqydCNpZ LgWmOS0tZxyKTRMTWTYJvDZ+Bc1x8VVhbSkDWP7BV0aRMgyyZlvVPbCFGOEB3y62HyI8 Gp8cqv+0Qlxd1ttDjEm8GTx8mI7wXP7AzoHxbqs/Var/FU8Wa5fbhLpG7z/hVX6ZYatU jW9qojphLeTzRlXFhzD/SnPhAsynRgEQQypNB6miWS7wPRzrvKovuuuMwrpx9w5tOkrZ GC+Q== X-Forwarded-Encrypted: i=1; AJvYcCWmrLbXxxEbUfeWacD7+u4ukObYgvcnIF3s+MmFUq+dJeBn+2nkBQAiVBq0VUWYQnRrOFLrHTCfC7Giwcg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw51KjsgiaQbfN27QwBjOzboInJPLc7beiHSJddvw1llyqZnTzB SDL11B3p+9wvMdhHq6C87IDBmuJavo67BdGjQnYCZG6ZrQcPNofpOleg X-Gm-Gg: ASbGncvIRpn/WEQSOxA+siHiTdGDgm/JbJWv2mECWTvNfMOiHSjvum5ndy0iD/ADFOW kGTTdIQD/ZF5y7dvtI7hbFnnbDkaVTPPb706POAzNEyHve10s93OyAiVL3YpkrseWxBGP5j6w63 76MAlkDuRYfBOWSQsh8Ky9s3Dmn2u7o8xLfcBgS6fT+RCvzzhlHAAFOH9fn/+9RmdJHHjaDNneX evz0Kw7aIj0Wv1XlwVAjIpw8Y/4nBdYz8EvwHSNh8TIg9hRGGdSk6VbLT//uoBlU84cxr8txg2p +gf/prLKXh6i2HJTGEVSeLO4HHhJNTNn/4eeWH5c1Ky7JUkeDaZo7ig5uiaMw/ZFWFA8c34Tmml mPps+giTlDzHJiuWW8WJehomjV8u3wKgmZOV+RFxzHRKLr1SJ1eivvCAnbuPYmntY2JBzeW2thD o6Lirty7UQYRWmEI8UgIXyLF2cIIA7 X-Google-Smtp-Source: AGHT+IGsTfGxHQxgZgJIIPv8CKF40nlldzUGw8hZ4M8Uj5zOydPQyKyC7DmLvOxFKHiXw3+JrzWB8w== X-Received: by 2002:a05:6000:220e:b0:42b:3978:1587 with SMTP id ffacd0b85a97d-42cc1d27ac6mr5941658f8f.36.1763833050375; Sat, 22 Nov 2025 09:37:30 -0800 (PST) Received: from ekhafagy-ROG-Strix.. ([197.46.88.62]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7fd8baesm18115824f8f.39.2025.11.22.09.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Nov 2025 09:37:29 -0800 (PST) From: Eslam Khafagy To: roderick.colenbrander@sony.com, jikos@kernel.org, bentiss@kernel.org, max@enpas.org Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Eslam Khafagy , syzbot+4f5f81e1456a1f645bf8@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: [PATCH v3] HID: memory leak in dualshock4_get_calibration_data Date: Sat, 22 Nov 2025 19:37:12 +0200 Message-ID: <20251122173712.76397-1-eslam.medhat1993@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: quoted-printable Content-Type: text/plain; charset="utf-8" Function dualshock4_get_calibration_data allocates memory to pointer buf .However, the function may exit prematurely due to transfer_failure in this case it does not handle freeing memory. This patch handles memory deallocation at exit. Reported-by: syzbot+4f5f81e1456a1f645bf8@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/691560c4.a70a0220.3124cb.0019.GAE@googl= e.com/T/ Tested-by: syzbot+4f5f81e1456a1f645bf8@syzkaller.appspotmail.com Fixes: 947992c7fa9e0 ("HID: playstation: DS4: Fix calibration workaround fo= r clone devices") Cc: stable@vger.kernel.org Signed-off-by: Eslam Khafagy Reviewed-by: Max Staudt --- v3: * Address issues reported by checkpatch and re-format commit message for better readability * kfree() is safe so no need to check for NULL pointer v2: https://lore.kernel.org/all/20251116022723.29857-1-eslam.medhat1993@gma= il.com/ * Adding tag "Cc: stable@vger.kernel.org" v1: https://lore.kernel.org/all/20251115022323.1395726-1-eslam.medhat1993@g= mail.com/ =20 drivers/hid/hid-playstation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 128aa6abd10b..05a8522ace4f 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -1994,9 +1994,6 @@ static int dualshock4_get_calibration_data(struct dua= lshock4 *ds4) acc_z_plus =3D get_unaligned_le16(&buf[31]); acc_z_minus =3D get_unaligned_le16(&buf[33]); =20 - /* Done parsing the buffer, so let's free it. */ - kfree(buf); - /* * Set gyroscope calibration and normalization parameters. * Data values will be normalized to 1/DS4_GYRO_RES_PER_DEG_S degree/s. @@ -2043,6 +2040,9 @@ static int dualshock4_get_calibration_data(struct dua= lshock4 *ds4) ds4->accel_calib_data[2].sens_denom =3D range_2g; =20 transfer_failed: + /* First free buf if still allocated */ + kfree(buf); + /* * Sanity check gyro calibration data. This is needed to prevent crashes * during report handling of virtual, clone or broken devices not impleme= nting --=20 2.43.0