From patchwork Fri Jan 17 14:16:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13943403 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (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 B2AA51E89C; Fri, 17 Jan 2025 14:16:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737123396; cv=none; b=LslpMxQ6FSyEeUUnO31+y34SdKqKF0oqsaw2Pa6KNQgYnYaEbjihzMEkQAbyeJeYZpGhpuxsrKhi1fPFnuND5ju8wluJwMh+aDfjJhTG662tidX5UIslrv840LKMTJtismLswtsqI9H6Kmha76HvtLBkcNFr0ENLIA1jxWd5s00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737123396; c=relaxed/simple; bh=/jrqqObcI+9mzm9OIPdnKRMAf0DMTi89JU7pGm/d9wA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T4w4oifw1DvKmIgvb49hZEk9Ne0kALBXkAdpPLiIOIBLEEU2AQfGdzZcW/UD2kiCIvki/z0+0dyQaqySkhwQD1LydFxSaL0jnsEkiJR2uoGaxui0orwabu7xLugrfULY1/3LfRG3KmN0fz4Jse35uUjECd4Jj+8AKj8QnTKp55o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=KON8Zid8; arc=none smtp.client-ip=212.227.17.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="KON8Zid8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737123381; x=1737728181; i=ps.report@gmx.net; bh=/jrqqObcI+9mzm9OIPdnKRMAf0DMTi89JU7pGm/d9wA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=KON8Zid8hrerfPMstZ7udmkv/1f4OGw6mLSjVHmgNowjxeC8EXfv72Q5c97Fymh7 Lg0BOpXf8Ig04iYauJ1Urd3tWA98pDZcklsMslEXZQAJ6nds9/QJg6qLQZgQpnhpL vK1hELBYqluSGE1y2PhK300nPbulTcTIlVSKcft74DJfmFQuHQL5l3s1JsMfm8MJq lR99QO1GT6iUcOdldK9O7nqhZYc8/CA6RSgFw8bGqiW7DncQfDOyQiNxRxo0s5Z8H MJj8q2X0f0EL2zDtGPjfha5FQ2XKUJJXYhC9mPLBwa8QtaGfYFhE0FMe31J3Xuo3/ Tq3Oywj2C/CAO1AMcw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.138]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MAfUe-1tfMiL1oE4-006p0d; Fri, 17 Jan 2025 15:16:21 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , =?utf-8?q?T?= =?utf-8?q?oke_H=C3=B8iland-J=C3=B8rgensen?= , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v1 3/5] net: pktgen: fix access outside of user given buffer in pktgen_thread_write() Date: Fri, 17 Jan 2025 15:16:11 +0100 Message-ID: <20250117141613.691452-4-ps.report@gmx.net> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250117141613.691452-1-ps.report@gmx.net> References: <20250117141613.691452-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:Ee9OMSptfaQVhKbBDX/bzUQ6/0WFIcJ1A+syMzJEUFnnpGdFlil xx7cNi/QeNZWfRcLYq1Ugjw80vmUFB0vQpOtTg1jAPCG1mD6k50ppY8Az5DpH4rJuRoX4e1 fMW7SXjpxBMCX4s3guvsmN85Ak85lDxG8I0fCUp3+dtfUeOWL19mkZzex5aidKhliFJ89sO nl9Q2BiJobZfx1qCfVcZQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:3Gq2azVcoio=;J49MGBfWgRSvdbn6Jloud5CacDU H22CLZ8LOmqpbz8XaX05N9OdlIar+oWSgvrTcXW3Ua0gUN0IVe+ey9Nu9/HI6GldW0W1jzWbm eiXegFVt2Ep7NfpvlnaphmSCttEW8fSilEbAu7RG8mbWLBeSLf/ILDvD+VwwvCRogbNu8ukur 4VMd3QZwl9XCAqGb5VfzLLUdmQOFcfRSm+w3aNlzYm0/N4EhnMBnmdXQQhDNQx3Uc3yGtvt4Z gtZWiVt4jPcyetGiJIRRCD77q457UB9UWFbfDU8dCY9LesmLjBA90Q2lv6NF6nG5/ZbC8bmPP jzFqX6Svhtta0UvJEI0cbWMIUxXS/5rkrdTze8D17z3I2OnD07V6Y1A/0Yk0wDPJG9sREOPre UiiC9TSipF0TKjOvPiGYEQ+QUgB2jalAcVER+HKvusrdgRmIv9qomos0bAZ7LTGzscEvXaLVB nYto7/qprsaNPr5lj+++n7f+7z5IYAK6kiQzcTxjJfypx1jHkbJTpbVR2FKkfP5TLywgh0+Rf aTbFyk1iWG9dibo6WFy8vY7d3UhkyiTSgxGOh75NYsWXVCIEWlIhaKILwL0XDlAwZnfBfGsKm qXVsJAN2Go7EvbwnsCLKreCTeK9DGc6Izcc9akn5bWBGq0g7dM2lQTPhoI1u30FUFGP8bzXJQ R/sWBh026ayr0tEMI2odQ1aplWeiAIwCVsL88nLCiWovADPJC9WLAp0J01K7WIUynKcgO43p4 rbOp55rnBNFwlnr7cmbDI+22VrIloZd/KD7HsDtxE30hgujGWk8GyXQFcw4SPhWLCMTJdUJxx hPWz/YSPIfNERdov7qL39hZxT3jRbvSBg/wsqtJQEmLXBEqplXtil2WBoH2KQ6RHyTNQqR0DR QYLfwnSo5nTrzdmVjT475Qzuur1KxBhIOqw4W12OzpwOdeVie0a5Nz6Dumz/4ptt9j7eVvKcj vmCs83r8v2kN5iWVr5T0aZ3Zyb5DiR/FtdEsau56kIBx+HkiQvE9m1auvde6QY7Lz5y7WRY0M zQAwmcxi1uycRj4kb7VT7dFNz2nce6DiSFEyMUoyqth1SPBz7eQLhP6cNijGT0sFJM3dcUUoH FIlcS8bV+huHShb/gRJ2rWTSEP55pRK4yRf5Pws8/yDq8CcpSBRokFZnaiShriwRzTC5dHes2 w9K8+IUj0o3Uc+Vy4+K7Yw0mmeB+cSKDvBDafkPLU6Q== X-Patchwork-Delegate: kuba@kernel.org Honour the user given buffer size for the strn_len() calls (otherwise strn_len() will access memory outside of the user given buffer). Signed-off-by: Peter Seiderer --- net/core/pktgen.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 4f8ec6c9bed4..9536f9c4d9ef 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -1897,8 +1897,8 @@ static ssize_t pktgen_thread_write(struct file *file, i = len; /* Read variable name */ - - len = strn_len(&user_buffer[i], sizeof(name) - 1); + max = min(sizeof(name) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1928,7 +1928,8 @@ static ssize_t pktgen_thread_write(struct file *file, if (!strcmp(name, "add_device")) { char f[32]; memset(f, 0, 32); - len = strn_len(&user_buffer[i], sizeof(f) - 1); + max = min(sizeof(f) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) { ret = len; goto out;