<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/drivers/usb/gadget/configfs.c, branch linux-6.9.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.</subtitle>
<id>https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-6.9.y</id>
<link rel='self' href='https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-6.9.y'/>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/'/>
<updated>2024-07-18T11:22:46Z</updated>
<entry>
<title>usb: gadget: configfs: Prevent OOB read/write in usb_string_copy()</title>
<updated>2024-07-18T11:22:46Z</updated>
<author>
<name>Lee Jones</name>
<email>lee@kernel.org</email>
</author>
<published>2024-07-05T07:43:39Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=eecfefad0953b2f31aaefa058f7f348ff39c4bba'/>
<id>urn:sha1:eecfefad0953b2f31aaefa058f7f348ff39c4bba</id>
<content type='text'>
commit 6d3c721e686ea6c59e18289b400cc95c76e927e0 upstream.

Userspace provided string 's' could trivially have the length zero. Left
unchecked this will firstly result in an OOB read in the form
`if (str[0 - 1] == '\n') followed closely by an OOB write in the form
`str[0 - 1] = '\0'`.

There is already a validating check to catch strings that are too long.
Let's supply an additional check for invalid strings that are too short.

Signed-off-by: Lee Jones &lt;lee@kernel.org&gt;
Cc: stable &lt;stable@kernel.org&gt;
Link: https://lore.kernel.org/r/20240705074339.633717-1-lee@kernel.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: configfs: Replace snprintf() with the safer scnprintf() variant</title>
<updated>2023-12-15T12:55:29Z</updated>
<author>
<name>Lee Jones</name>
<email>lee@kernel.org</email>
</author>
<published>2023-12-13T16:42:30Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=0466e7e693efe6647f23532529a9c41a1fa5f4ac'/>
<id>urn:sha1:0466e7e693efe6647f23532529a9c41a1fa5f4ac</id>
<content type='text'>
There is a general misunderstanding amongst engineers that {v}snprintf()
returns the length of the data *actually* encoded into the destination
array.  However, as per the C99 standard {v}snprintf() really returns
the length of the data that *would have been* written if there were
enough space for it.  This misunderstanding has led to buffer-overruns
in the past.  It's generally considered safer to use the {v}scnprintf()
variants in their place (or even sprintf() in simple cases).  So let's
do that.

Link: https://lwn.net/Articles/69419/
Link: https://github.com/KSPP/linux/issues/105
Signed-off-by: Lee Jones &lt;lee@kernel.org&gt;
Link: https://lore.kernel.org/r/20231213164246.1021885-2-lee@kernel.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: Remove snprintf() from sysfs call-backs and replace with sysfs_emit()</title>
<updated>2023-12-04T13:25:17Z</updated>
<author>
<name>Lee Jones</name>
<email>lee@kernel.org</email>
</author>
<published>2023-11-30T10:54:38Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=38168e2de320b9c12132eb72cf1f1d3d411fe38c'/>
<id>urn:sha1:38168e2de320b9c12132eb72cf1f1d3d411fe38c</id>
<content type='text'>
Since snprintf() has the documented, but still rather strange trait of
returning the length of the data that *would have been* written to the
array if space were available, rather than the arguably more useful
length of data *actually* written, it is usually considered wise to use
something else instead in order to avoid confusion.

In the case of sysfs call-backs, new wrappers exist that do just that.

This patch replaces just one use of snprintf() found in the sysfs
.show() call-back with the new sysfs_emit() helper.

Link: https://lwn.net/Articles/69419/
Link: https://github.com/KSPP/linux/issues/105
Cc: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Cc: linux-usb@vger.kernel.org
Signed-off-by: Lee Jones &lt;lee@kernel.org&gt;
Link: https://lore.kernel.org/r/20231130105459.3208986-5-lee@kernel.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: Properly configure the device for remote wakeup</title>
<updated>2023-03-29T08:27:00Z</updated>
<author>
<name>Elson Roy Serrao</name>
<email>quic_eserrao@quicinc.com</email>
</author>
<published>2023-03-24T21:47:57Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=b93c2a68f3d9dc98ec30dcb342ae47c1c8d09d18'/>
<id>urn:sha1:b93c2a68f3d9dc98ec30dcb342ae47c1c8d09d18</id>
<content type='text'>
The wakeup bit in the bmAttributes field indicates whether the device
is configured for remote wakeup. But this field should be allowed to
set only if the UDC supports such wakeup mechanism. So configure this
field based on UDC capability. Also inform the UDC whether the device
is configured for remote wakeup by implementing a gadget op.

Reviewed-by: Thinh Nguyen &lt;Thinh.Nguyen@synopsys.com&gt;
Signed-off-by: Elson Roy Serrao &lt;quic_eserrao@quicinc.com&gt;
Link: https://lore.kernel.org/r/1679694482-16430-2-git-send-email-quic_eserrao@quicinc.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: configfs: Fix set but not used variable warning</title>
<updated>2023-02-09T11:12:47Z</updated>
<author>
<name>Daniel Scally</name>
<email>dan.scally@ideasonboard.com</email>
</author>
<published>2023-02-09T09:43:59Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=8488a831e0c4d59528d20713a14cb8958af15bfe'/>
<id>urn:sha1:8488a831e0c4d59528d20713a14cb8958af15bfe</id>
<content type='text'>
Fix a -Wunused-but-set-variable warning in gadget_string_s_store()

Fixes: 15a7cf8caabe ("usb: gadget: configfs: Support arbitrary string descriptors")
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: Daniel Scally &lt;dan.scally@ideasonboard.com&gt;
Link: https://lore.kernel.org/r/20230209094359.1549629-1-dan.scally@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: configfs: Attach arbitrary strings to cdev</title>
<updated>2023-02-07T07:46:36Z</updated>
<author>
<name>Daniel Scally</name>
<email>dan.scally@ideasonboard.com</email>
</author>
<published>2023-02-06T16:17:58Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=c033563220e0f7a82f4ae8d698284cced94fd6cf'/>
<id>urn:sha1:c033563220e0f7a82f4ae8d698284cced94fd6cf</id>
<content type='text'>
Attach any arbitrary strings that are defined to the composite dev.
We handle the old-style manufacturer, product and serialnumbers
strings in the same function for simplicity.

Signed-off-by: Daniel Scally &lt;dan.scally@ideasonboard.com&gt;
Link: https://lore.kernel.org/r/20230206161802.892954-8-dan.scally@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: configfs: Support arbitrary string descriptors</title>
<updated>2023-02-07T07:46:36Z</updated>
<author>
<name>Daniel Scally</name>
<email>dan.scally@ideasonboard.com</email>
</author>
<published>2023-02-06T16:17:57Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=15a7cf8caabee4613764abe7814dd3162cb64137'/>
<id>urn:sha1:15a7cf8caabee4613764abe7814dd3162cb64137</id>
<content type='text'>
Add a framework to allow users to define arbitrary string descriptors
for a USB Gadget. This is modelled as a new type of config item rather
than as hardcoded attributes so as to be as flexible as possible.

Signed-off-by: Daniel Scally &lt;dan.scally@ideasonboard.com&gt;
Link: https://lore.kernel.org/r/20230206161802.892954-7-dan.scally@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: configfs: Rename struct gadget_strings</title>
<updated>2023-02-07T07:46:36Z</updated>
<author>
<name>Daniel Scally</name>
<email>dan.scally@ideasonboard.com</email>
</author>
<published>2023-02-06T16:17:56Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=6e2a512d9532c51889a2601cba338c4673a09374'/>
<id>urn:sha1:6e2a512d9532c51889a2601cba338c4673a09374</id>
<content type='text'>
The struct gadget_strings really represents a single language in
configfs. Rename it to make that more clear.

Signed-off-by: Daniel Scally &lt;dan.scally@ideasonboard.com&gt;
Link: https://lore.kernel.org/r/20230206161802.892954-6-dan.scally@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: configfs: Use memcpy_and_pad()</title>
<updated>2023-02-06T12:46:41Z</updated>
<author>
<name>Andy Shevchenko</name>
<email>andriy.shevchenko@linux.intel.com</email>
</author>
<published>2023-02-02T15:17:36Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=9c0e6fbda803dfd66c05c1f683069b46bd4cbba0'/>
<id>urn:sha1:9c0e6fbda803dfd66c05c1f683069b46bd4cbba0</id>
<content type='text'>
Instead of zeroing some memory and then copying data in part or all of it,
use memcpy_and_pad().
This avoids writing some memory twice and should save a few cycles.

Signed-off-by: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Link: https://lore.kernel.org/r/20230202151736.64552-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: configfs: Restrict symlink creation is UDC already binded</title>
<updated>2023-02-02T10:14:14Z</updated>
<author>
<name>Udipto Goswami</name>
<email>quic_ugoswami@quicinc.com</email>
</author>
<published>2023-02-01T13:23:08Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=89e7252d6c7e7eeb31971cd7df987316ecc64ff5'/>
<id>urn:sha1:89e7252d6c7e7eeb31971cd7df987316ecc64ff5</id>
<content type='text'>
During enumeration or composition switch,a userspace process
agnostic of the conventions of configs can try to create function
symlinks even after the UDC is bound to current config which is
not correct. Potentially it can create duplicates within the
current config.

Prevent this by adding a check if udc_name already exists, then bail
out of cfg_link.

Following is an example:

Step1:
ln -s X1 ffs.a
--&gt;cfg_link
--&gt; usb_get_function(ffs.a)
	-&gt;ffs_alloc

	CFG-&gt;FUNC_LIST: &lt;ffs.a&gt;
	C-&gt;FUNCTION: &lt;empty&gt;

Step2:
echo udc.name &gt; /config/usb_gadget/g1/UDC
--&gt; UDC_store
	-&gt;composite_bind
	-&gt;usb_add_function

	CFG-&gt;FUNC_LIST: &lt;empty&gt;
	C-&gt;FUNCTION: &lt;ffs.a&gt;

Step3:
ln -s Y1 ffs.a
--&gt;cfg_link
--&gt;usb_get_function(ffs.a)
	-&gt;ffs_alloc

	CFG-&gt;FUNC_LIST: &lt;ffs.a&gt;
	C-&gt;FUNCTION: &lt;ffs.a&gt;

both the lists corresponds to the same function instance ffs.a
but the usb_function* pointer is different because in step 3
ffs_alloc has created a new reference to usb_function* for
ffs.a and added it to cfg_list.

Step4:
Now a composition switch involving &lt;ffs.b,ffs.a&gt; is executed.

the composition switch will involve 3 things:
	1. unlinking the previous functions existing
	2. creating new symlinks
	3. writing UDC

However, the composition switch is generally taken care by
userspace process which creates the symlinks in its own
nomenclature(X*) and removes only those.
So it won't be able to remove Y1 which user had created
by own.

Due to this the new symlinks cannot be created for ffs.a
since the entry already exists in CFG-&gt;FUNC_LIST.

The state of the CFG-&gt;FUNC_LIST is as follows:
	CFG-&gt;FUNC_LIST: &lt;ffs.a&gt;

Fixes: 88af8bbe4ef7 ("usb: gadget: the start of the configfs interface")
Signed-off-by: Krishna Kurapati PSSNV &lt;quic_kriskura@quicinc.com&gt;
Signed-off-by: Udipto Goswami &lt;quic_ugoswami@quicinc.com&gt;
Link: https://lore.kernel.org/r/20230201132308.31523-1-quic_ugoswami@quicinc.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
