5.4.229-rc1 review
Subsystems (8)
Greg Kroah-Hartman
maintainerPATCH 464/658 HID: plantronics: Additional PIDs for double volume key presses quirk
In reply to Greg Kroah-HartmanFrom: Terry Junge <[email protected]>
[ Upstream commit 3d57f36c89d8ba32b2c312f397a37fd1a2dc7cfc ]
I no longer work for Plantronics (aka Poly, aka HP) and do not have access to the headsets in order to test. However, as noted by Maxim, the other 32xx models that share the same base code set as the 3220 would need the same quirk. This patch adds the PIDs for the rest of the Blackwire 32XX product family that require the quirk.
Plantronics Blackwire 3210 Series (047f:c055)
Plantronics Blackwire 3215 Series (047f:c057)
Plantronics Blackwire 3225 Series (047f:c058)
Quote from previous patch by Maxim Mikityanskiy Plantronics Blackwire 3220 Series (047f:c056) sends HID reports twice for each volume key press. This patch adds a quirk to hid-plantronics for this product ID, which will ignore the second volume key press if it happens within 5 ms from the last one that was handled.
The patch was tested on the mentioned model only, it shouldn't affect other models, however, this quirk might be needed for them too. Auto-repeat (when a key is held pressed) is not affected, because the rate is about 3 times per second, which is far less frequent than once in 5 ms.
End quote
--- drivers/hid/hid-ids.h | 3 +++ drivers/hid/hid-plantronics.c | 9 +++++++++ 2 files changed, 12 insertions(+)
drivers/hid/hid-ids.h +3 -0
@@ -938,7 +938,10 @@#define USB_DEVICE_ID_ORTEK_IHOME_IMAC_A210S 0x8003#define USB_VENDOR_ID_PLANTRONICS 0x047f +#define USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3210_SERIES 0xc055#define USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3220_SERIES 0xc056 +#define USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3215_SERIES 0xc057 +#define USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3225_SERIES 0xc058#define USB_VENDOR_ID_PANASONIC 0x04da#define USB_DEVICE_ID_PANABOARD_UBT780 0x1044
drivers/hid/hid-plantronics.c +9 -0
@@ -198,9 +198,18 @@ static int plantronics_probe(struct hid_device *hdev, }static const struct hid_device_id plantronics_devices[] = { + {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS , +USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3210_SERIES ), + .driver_data =PLT_QUIRK_DOUBLE_VOLUME_KEYS }, {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS ,USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3220_SERIES ), .driver_data =PLT_QUIRK_DOUBLE_VOLUME_KEYS }, + {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS , +USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3215_SERIES ), + .driver_data =PLT_QUIRK_DOUBLE_VOLUME_KEYS }, + {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS , +USB_DEVICE_ID_PLANTRONICS_BLACKWIRE_3225_SERIES ), + .driver_data =PLT_QUIRK_DOUBLE_VOLUME_KEYS }, {HID_USB_DEVICE (USB_VENDOR_ID_PLANTRONICS ,HID_ANY_ID ) }, { } };
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 465/658 hfsplus: fix bug causing custom uid and gid being unable to be assigned with mount
In reply to Greg Kroah-HartmanFrom: Aditya Garg <[email protected]>
commit 9f2b5debc07073e6dfdd774e3594d0224b991927 upstream.
Despite specifying UID and GID in mount command, the specified UID and GID were not being assigned. This patch fixes this issue.
--- fs/hfsplus/hfsplus_fs.h | 2 ++ fs/hfsplus/inode.c | 4 ++-- fs/hfsplus/options.c | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-)
fs/hfsplus/hfsplus_fs.h +2 -0
@@ -198,6 +198,8 @@ struct hfsplus_sb_info {#define HFSPLUS_SB_HFSX 3#define HFSPLUS_SB_CASEFOLD 4#define HFSPLUS_SB_NOBARRIER 5 +#define HFSPLUS_SB_UID 6 +#define HFSPLUS_SB_GID 7static inline struct hfsplus_sb_info *HFSPLUS_SB (struct super_block *sb) {
fs/hfsplus/inode.c +2 -2
@@ -187,11 +187,11 @@ static void hfsplus_get_perms(struct ino mode =be16_to_cpu (perms->mode);i_uid_write (inode,be32_to_cpu (perms->owner)); -if (!i_uid_read (inode) && !mode) +if ((test_bit (HFSPLUS_SB_UID , &sbi->flags)) || (!i_uid_read (inode) && !mode)) inode->i_uid = sbi->uid;i_gid_write (inode,be32_to_cpu (perms->group)); -if (!i_gid_read (inode) && !mode) +if ((test_bit (HFSPLUS_SB_GID , &sbi->flags)) || (!i_gid_read (inode) && !mode)) inode->i_gid = sbi->gid;if (dir) {
fs/hfsplus/options.c +4 -0
@@ -140,6 +140,8 @@ int hfsplus_parse_options(char *input, sif (!uid_valid (sbi->uid)) {pr_err ("invalid uid specified\n" );return 0 ; + }else { +set_bit (HFSPLUS_SB_UID , &sbi->flags); }break ;case opt_gid:
@@ -151,6 +153,8 @@ int hfsplus_parse_options(char *input, sif (!gid_valid (sbi->gid)) {pr_err ("invalid gid specified\n" );return 0 ; + }else { +set_bit (HFSPLUS_SB_GID , &sbi->flags); }break ;case opt_part:
Greg Kroah-Hartman
maintainerPATCH 466/658 ovl: Use ovl mounters fsuid and fsgid in ovl_link()
In reply to Greg Kroah-HartmanFrom: Zhang Tianci <[email protected]>
commit 5b0db51215e895a361bc63132caa7cca36a53d6a upstream.
There is a wrong case of link() on overlay:
$ mkdir /lower /fuse /merge
$ mount -t fuse /fuse
$ mkdir /fuse/upper /fuse/work
$ mount -t overlay /merge -o lowerdir=/lower,upperdir=/fuse/upper,\
workdir=work
$ touch /merge/file
$ chown bin.bin /merge/file // the file's caller becomes "bin"
$ ln /merge/file /merge/lnkfileThen we will get an error(EACCES) because fuse daemon checks the link()'s caller is "bin", it denied this request.
In the changing history of ovl_link(), there are two key commits:
The first is commit bb0d2b8ad296 ("ovl: fix sgid on directory") which overrides the cred's fsuid/fsgid using the new inode. The new inode's owner is initialized by inode_init_owner(), and inode->fsuid is assigned to the current user. So the override fsuid becomes the current user. We know link() is actually modifying the directory, so the caller must have the MAY_WRITE permission on the directory. The current caller may should have this permission. This is acceptable to use the caller's fsuid.
The second is commit 51f7e52dc943 ("ovl: share inode for hard link") which removed the inode creation in ovl_link(). This commit move inode_init_owner() into ovl_create_object(), so the ovl_link() just give the old inode to ovl_create_or_link(). Then the override fsuid becomes the old inode's fsuid, neither the caller nor the overlay's mounter! So this is incorrect.
Fix this bug by using ovl mounter's fsuid/fsgid to do underlying fs's link().
--- fs/overlayfs/dir.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-)
fs/overlayfs/dir.c +30 -16
@@ -557,28 +557,42 @@ static int ovl_create_or_link(struct den goto out_revert_creds; } - err = -ENOMEM ; - override_cred =prepare_creds (); -if (override_cred) { +if (!attr->hardlink) { + err = -ENOMEM ; + override_cred =prepare_creds (); +if (!override_cred) + goto out_revert_creds; +/* +* In the creation cases(create, mkdir, mknod, symlink), +* ovl should transfer current's fs{u,g}id to underlying +* fs. Because underlying fs want to initialize its new +* inode owner using current's fs{u,g}id. And in this +* case, the @inode is a new inode that is initialized +* in inode_init_owner() to current's fs{u,g}id. So use +* the inode's i_{u,g}id to override the cred's fs{u,g}id. +* +* But in the other hardlink case, ovl_link() does not +* create a new inode, so just use the ovl mounter's +* fs{u,g}id. +*/ override_cred->fsuid = inode->i_uid; override_cred->fsgid = inode->i_gid; -if (!attr->hardlink) { - err =security_dentry_create_files_as (dentry, - attr->mode, &dentry->d_name, old_cred, - override_cred); -if (err) { -put_cred (override_cred); - goto out_revert_creds; - } + err =security_dentry_create_files_as (dentry, + attr->mode, &dentry->d_name, old_cred, + override_cred); +if (err) { +put_cred (override_cred); + goto out_revert_creds; }put_cred (override_creds (override_cred));put_cred (override_cred); - -if (!ovl_dentry_is_whiteout (dentry)) - err =ovl_create_upper (dentry, inode, attr); -else - err =ovl_create_over_whiteout (dentry, inode, attr); } + +if (!ovl_dentry_is_whiteout (dentry)) + err =ovl_create_upper (dentry, inode, attr); +else + err =ovl_create_over_whiteout (dentry, inode, attr); + out_revert_creds:revert_creds (old_cred);return err;
Greg Kroah-Hartman
maintainerPATCH 467/658 ALSA: line6: correct midi status byte when receiving data from podxt
In reply to Greg Kroah-HartmanFrom: Artem Egorkine <[email protected]>
commit 8508fa2e7472f673edbeedf1b1d2b7a6bb898ecc upstream.
A PODxt device sends 0xb2, 0xc2 or 0xf2 as a status byte for MIDI messages over USB that should otherwise have a 0xb0, 0xc0 or 0xf0 status byte. This is usually corrected by the driver on other OSes.
This fixes MIDI sysex messages sent by PODxt.
[ tiwai: fixed white spaces ]
--- sound/usb/line6/driver.c | 3 ++- sound/usb/line6/midi.c | 3 ++- sound/usb/line6/midibuf.c | 25 +++++++++++++++++-------- sound/usb/line6/midibuf.h | 5 ++++- sound/usb/line6/pod.c | 3 ++- 5 files changed, 27 insertions(+), 12 deletions(-)
sound/usb/line6/driver.c +2 -1
@@ -303,7 +303,8 @@ static void line6_data_received(struct ufor (;;) { done =line6_midibuf_read (mb, line6->buffer_message, -LINE6_MIDI_MESSAGE_MAXLEN ); +LINE6_MIDI_MESSAGE_MAXLEN , +LINE6_MIDIBUF_READ_RX );if (done <=0 )break ;
sound/usb/line6/midi.c +2 -1
@@ -56,7 +56,8 @@ static void line6_midi_transmit(struct sfor (;;) { done =line6_midibuf_read (mb, chunk, -LINE6_FALLBACK_MAXPACKETSIZE ); +LINE6_FALLBACK_MAXPACKETSIZE , +LINE6_MIDIBUF_READ_TX );if (done ==0 )break ;
sound/usb/line6/midibuf.c +17 -8
@@ -9,6 +9,7 @@#include "midibuf.h" +static int midibuf_message_length (unsigned char code) {int message_length;
@@ -20,12 +21,7 @@ static int midibuf_message_length(unsign message_length = length[(code >>4 ) -8 ]; }else { -/* -Note that according to the MIDI specification 0xf2 is -the "Song Position Pointer", but this is used by Line 6 -to send sysex messages to the host. -*/ -static const int length[] = {-1 ,2 ,-1 ,2 ,-1 ,-1 ,1 ,1 ,1 ,1 , +static const int length[] = {-1 ,2 ,2 ,2 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,1 }; message_length = length[code &0x0f ];
@@ -125,7 +121,7 @@ int line6_midibuf_write(struct midi_buff }int line6_midibuf_read (struct midi_buffer *this,unsigned char *data, -int length) +int length,int read_type) {int bytes_used;int length1, length2;
@@ -148,9 +144,22 @@ int line6_midibuf_read(struct midi_buffe length1 = this->size - this->pos_read; -/* check MIDI command length */ command = this->buf[this->pos_read]; +/* +PODxt always has status byte lower nibble set to 0010, +when it means to send 0000, so we correct if here so +that control/program changes come on channel 1 and +sysex message status byte is correct +*/ +if (read_type ==LINE6_MIDIBUF_READ_RX ) { +if (command ==0xb2 || command ==0xc2 || command ==0xf2 ) { +unsigned char fixed = command &0xf0 ; + this->buf[this->pos_read] = fixed; + command = fixed; + } + } +/* check MIDI command length */ if (command &0x80 ) { midi_length =midibuf_message_length (command); this->command_prev = command;
sound/usb/line6/midibuf.h +4 -1
@@ -8,6 +8,9 @@ #ifndef MIDIBUF_H #define MIDIBUF_H +#define LINE6_MIDIBUF_READ_TX 0 +#define LINE6_MIDIBUF_READ_RX 1 + struct midi_buffer { unsigned char *buf; int size;
@@ -23,7 +26,7 @@ extern void line6_midibuf_destroy(structextern int line6_midibuf_ignore (struct midi_buffer *mb,int length);extern int line6_midibuf_init (struct midi_buffer *mb,int size,int split);extern int line6_midibuf_read (struct midi_buffer *mb,unsigned char *data, -int length); +int length,int read_type);extern void line6_midibuf_reset (struct midi_buffer *mb);extern int line6_midibuf_write (struct midi_buffer *mb,unsigned char *data,int length);
sound/usb/line6/pod.c +2 -1
@@ -159,8 +159,9 @@ static struct line6_pcm_properties pod_p .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */ }; +static const char pod_version_header[] = { -0xf2 ,0x7e ,0x7f ,0x06 ,0x02 +0xf0 ,0x7e ,0x7f ,0x06 ,0x02 }; static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
Greg Kroah-Hartman
maintainerPATCH 468/658 ALSA: line6: fix stack overflow in line6_midi_transmit
In reply to Greg Kroah-HartmanFrom: Artem Egorkine <[email protected]>
commit b8800d324abb50160560c636bfafe2c81001b66c upstream.
Correctly calculate available space including the size of the chunk buffer. This fixes a buffer overflow when multiple MIDI sysex messages are sent to a PODxt device.
--- sound/usb/line6/midi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/usb/line6/midi.c +2 -1
@@ -44,7 +44,8 @@ static void line6_midi_transmit(struct sint req, done;for (;;) { - req =min (line6_midibuf_bytes_free (mb), line6->max_packet_size); + req =min3 (line6_midibuf_bytes_free (mb), line6->max_packet_size, +LINE6_FALLBACK_MAXPACKETSIZE ); done =snd_rawmidi_transmit_peek (substream, chunk, req);if (done ==0 )
Greg Kroah-Hartman
maintainerPATCH 469/658 pnode: terminate at peers of source
In reply to Greg Kroah-HartmanFrom: Christian Brauner <[email protected]>
commit 11933cf1d91d57da9e5c53822a540bbdc2656c16 upstream.
The propagate_mnt() function handles mount propagation when creating mounts and propagates the source mount tree @source_mnt to all applicable nodes of the destination propagation mount tree headed by @dest_mnt.
Unfortunately it contains a bug where it fails to terminate at peers of @source_mnt when looking up copies of the source mount that become masters for copies of the source mount tree mounted on top of slaves in the destination propagation tree causing a NULL dereference.
Once the mechanics of the bug are understood it's easy to trigger. Because of unprivileged user namespaces it is available to unprivileged users.
While fixing this bug we've gotten confused multiple times due to unclear terminology or missing concepts. So let's start this with some clarifications:
* The terms "master" or "peer" denote a shared mount. A shared mount belongs to a peer group.
* A peer group is a set of shared mounts that propagate to each other. They are identified by a peer group id. The peer group id is available in @shared_mnt->mnt_group_id.
Shared mounts within the same peer group have the same peer group id. The peers in a peer group can be reached via @shared_mnt->mnt_share.
* The terms "slave mount" or "dependent mount" denote a mount that receives propagation from a peer in a peer group. IOW, shared mounts may have slave mounts and slave mounts have shared mounts as their master. Slave mounts of a given peer in a peer group are listed on that peers slave list available at @shared_mnt->mnt_slave_list.
* The term "master mount" denotes a mount in a peer group. IOW, it denotes a shared mount or a peer mount in a peer group. The term "master mount" - or "master" for short - is mostly used when talking in the context of slave mounts that receive propagation from a master mount. A master mount of a slave identifies the closest peer group a slave mount receives propagation from. The master mount of a slave can be identified via @slave_mount->mnt_master. Different slaves may point to different masters in the same peer group.
* Multiple peers in a peer group can have non-empty ->mnt_slave_lists. Non-empty ->mnt_slave_lists of peers don't intersect. Consequently, to ensure all slave mounts of a peer group are visited the ->mnt_slave_lists of all peers in a peer group have to be walked.
* Slave mounts point to a peer in the closest peer group they receive propagation from via @slave_mnt->mnt_master (see above). Together with these peers they form a propagation group (see below). The closest peer group can thus be identified through the peer group id @slave_mnt->mnt_master->mnt_group_id of the peer/master that a slave mount receives propagation from.
* A shared-slave mount is a slave mount to a peer group pg1 while also a peer in another peer group pg2. IOW, a peer group may receive propagation from another peer group.
If a peer group pg1 is a slave to another peer group pg2 then all peers in peer group pg1 point to the same peer in peer group pg2 via ->mnt_master. IOW, all peers in peer group pg1 appear on the same ->mnt_slave_list. IOW, they cannot be slaves to different peer groups.
* A pure slave mount is a slave mount that is a slave to a peer group but is not a peer in another peer group.
* A propagation group denotes the set of mounts consisting of a single peer group pg1 and all slave mounts and shared-slave mounts that point to a peer in that peer group via ->mnt_master. IOW, all slave mounts such that @slave_mnt->mnt_master->mnt_group_id is equal to @shared_mnt->mnt_group_id.
The concept of a propagation group makes it easier to talk about a single propagation level in a propagation tree.
For example, in propagate_mnt() the immediate peers of @dest_mnt and all slaves of @dest_mnt's peer group form a propagation group propg1. So a shared-slave mount that is a slave in propg1 and that is a peer in another peer group pg2 forms another propagation group propg2 together with all slaves that point to that shared-slave mount in their ->mnt_master.
* A propagation tree refers to all mounts that receive propagation starting from a specific shared mount.
For example, for propagate_mnt() @dest_mnt is the start of a propagation tree. The propagation tree ecompasses all mounts that receive propagation from @dest_mnt's peer group down to the leafs.
With that out of the way let's get to the actual algorithm.
We know that @dest_mnt is guaranteed to be a pure shared mount or a shared-slave mount. This is guaranteed by a check in attach_recursive_mnt(). So propagate_mnt() will first propagate the source mount tree to all peers in @dest_mnt's peer group:
for (n = next_peer(dest_mnt); n != dest_mnt; n = next_peer(n)) {
ret = propagate_one(n);
if (ret)
goto out;
}Notice, that the peer propagation loop of propagate_mnt() doesn't propagate @dest_mnt itself. @dest_mnt is mounted directly in attach_recursive_mnt() after we propagated to the destination propagation tree.
The mount that will be mounted on top of @dest_mnt is @source_mnt. This copy was created earlier even before we entered attach_recursive_mnt() and doesn't concern us a lot here.
It's just important to notice that when propagate_mnt() is called @source_mnt will not yet have been mounted on top of @dest_mnt. Thus, @source_mnt->mnt_parent will either still point to @source_mnt or - in the case @source_mnt is moved and thus already attached - still to its former parent.
For each peer @m in @dest_mnt's peer group propagate_one() will create a new copy of the source mount tree and mount that copy @child on @m such that @child->mnt_parent points to @m after propagate_one() returns.
propagate_one() will stash the last destination propagation node @m in @last_dest and the last copy it created for the source mount tree in @last_source.
Hence, if we call into propagate_one() again for the next destination propagation node @m, @last_dest will point to the previous destination propagation node and @last_source will point to the previous copy of the source mount tree and mounted on @last_dest.
Each new copy of the source mount tree is created from the previous copy of the source mount tree. This will become important later.
The peer loop in propagate_mnt() is straightforward. We iterate through the peers copying and updating @last_source and @last_dest as we go through them and mount each copy of the source mount tree @child on a peer @m in @dest_mnt's peer group.
After propagate_mnt() handled the peers in @dest_mnt's peer group propagate_mnt() will propagate the source mount tree down the propagation tree that @dest_mnt's peer group propagates to:
for (m = next_group(dest_mnt, dest_mnt); m;
m = next_group(m, dest_mnt)) {
/* everything in that slave group */
n = m;
do {
ret = propagate_one(n);
if (ret)
goto out;
n = next_peer(n);
} while (n != m);
}The next_group() helper will recursively walk the destination propagation tree, descending into each propagation group of the propagation tree.
The important part is that it takes care to propagate the source mount tree to all peers in the peer group of a propagation group before it propagates to the slaves to those peers in the propagation group. IOW, it creates and mounts copies of the source mount tree that become masters before it creates and mounts copies of the source mount tree that become slaves to these masters.
It is important to remember that propagating the source mount tree to each mount @m in the destination propagation tree simply means that we create and mount new copies @child of the source mount tree on @m such that @child->mnt_parent points to @m.
Since we know that each node @m in the destination propagation tree headed by @dest_mnt's peer group will be overmounted with a copy of the source mount tree and since we know that the propagation properties of each copy of the source mount tree we create and mount at @m will mostly mirror the propagation properties of @m. We can use that information to create and mount the copies of the source mount tree that become masters before their slaves.
The easy case is always when @m and @last_dest are peers in a peer group of a given propagation group. In that case we know that we can simply copy @last_source without having to figure out what the master for the new copy @child of the source mount tree needs to be as we've done that in a previous call to propagate_one().
The hard case is when we're dealing with a slave mount or a shared-slave mount @m in a destination propagation group that we need to create and mount a copy of the source mount tree on.
For each propagation group in the destination propagation tree we propagate the source mount tree to we want to make sure that the copies @child of the source mount tree we create and mount on slaves @m pick an ealier copy of the source mount tree that we mounted on a master @m of the destination propagation group as their master. This is a mouthful but as far as we can tell that's the core of it all.
But, if we keep track of the masters in the destination propagation tree @m we can use the information to find the correct master for each copy of the source mount tree we create and mount at the slaves in the destination propagation tree @m.
Let's walk through the base case as that's still fairly easy to grasp.
If we're dealing with the first slave in the propagation group that @dest_mnt is in then we don't yet have marked any masters in the destination propagation tree.
We know the master for the first slave to @dest_mnt's peer group is simple @dest_mnt. So we expect this algorithm to yield a copy of the source mount tree that was mounted on a peer in @dest_mnt's peer group as the master for the copy of the source mount tree we want to mount at the first slave @m:
for (n = m; ; n = p) {
p = n->mnt_master;
if (p == dest_master || IS_MNT_MARKED(p))
break;
}For the first slave we walk the destination propagation tree all the way up to a peer in @dest_mnt's peer group. IOW, the propagation hierarchy can be walked by walking up the @mnt->mnt_master hierarchy of the destination propagation tree @m. We will ultimately find a peer in @dest_mnt's peer group and thus ultimately @dest_mnt->mnt_master.
Btw, here the assumption we listed at the beginning becomes important. Namely, that peers in a peer group pg1 that are slaves in another peer group pg2 appear on the same ->mnt_slave_list. IOW, all slaves who are peers in peer group pg1 point to the same peer in peer group pg2 via their ->mnt_master. Otherwise the termination condition in the code above would be wrong and next_group() would be broken too.
So the first iteration sets:
n = m;
p = n->mnt_master;
such that @p now points to a peer or @dest_mnt itself. We walk up one more level since we don't have any marked mounts. So we end up with:
n = dest_mnt;
p = dest_mnt->mnt_master;
If @dest_mnt's peer group is not slave to another peer group then @p is now NULL. If @dest_mnt's peer group is a slave to another peer group then @p now points to @dest_mnt->mnt_master points which is a master outside the propagation tree we're dealing with.
Now we need to figure out the master for the copy of the source mount tree we're about to create and mount on the first slave of @dest_mnt's peer group:
do {
struct mount *parent = last_source->mnt_parent;
if (last_source == first_source)
break;
done = parent->mnt_master == p;
if (done && peers(n, parent))
break;
last_source = last_source->mnt_master;
} while (!done);We know that @last_source->mnt_parent points to @last_dest and @last_dest is the last peer in @dest_mnt's peer group we propagated to in the peer loop in propagate_mnt().
Consequently, @last_source is the last copy we created and mount on that last peer in @dest_mnt's peer group. So @last_source is the master we want to pick.
We know that @last_source->mnt_parent->mnt_master points to @last_dest->mnt_master. We also know that @last_dest->mnt_master is either NULL or points to a master outside of the destination propagation tree and so does @p. Hence:
done = parent->mnt_master == p;
is trivially true in the base condition.
We also know that for the first slave mount of @dest_mnt's peer group that @last_dest either points @dest_mnt itself because it was initialized to:
last_dest = dest_mnt;
at the beginning of propagate_mnt() or it will point to a peer of @dest_mnt in its peer group. In both cases it is guaranteed that on the first iteration @n and @parent are peers (Please note the check for peers here as that's important.):
if (done && peers(n, parent))
break;
So, as we expected, we select @last_source, which referes to the last copy of the source mount tree we mounted on the last peer in @dest_mnt's peer group, as the master of the first slave in @dest_mnt's peer group. The rest is taken care of by clone_mnt(last_source, ...). We'll skip over that part otherwise this becomes a blogpost.
At the end of propagate_mnt() we now mark @m->mnt_master as the first master in the destination propagation tree that is distinct from @dest_mnt->mnt_master. IOW, we mark @dest_mnt itself as a master.
By marking @dest_mnt or one of it's peers we are able to easily find it again when we later lookup masters for other copies of the source mount tree we mount copies of the source mount tree on slaves @m to @dest_mnt's peer group. This, in turn allows us to find the master we selected for the copies of the source mount tree we mounted on master in the destination propagation tree again.
The important part is to realize that the code makes use of the fact that the last copy of the source mount tree stashed in @last_source was mounted on top of the previous destination propagation node @last_dest. What this means is that @last_source allows us to walk the destination propagation hierarchy the same way each destination propagation node @m does.
If we take @last_source, which is the copy of @source_mnt we have mounted on @last_dest in the previous iteration of propagate_one(), then we know @last_source->mnt_parent points to @last_dest but we also know that as we walk through the destination propagation tree that @last_source->mnt_master will point to an earlier copy of the source mount tree we mounted one an earlier destination propagation node @m.
IOW, @last_source->mnt_parent will be our hook into the destination propagation tree and each consecutive @last_source->mnt_master will lead us to an earlier propagation node @m via @last_source->mnt_master->mnt_parent.
Hence, by walking up @last_source->mnt_master, each of which is mounted on a node that is a master @m in the destination propagation tree we can also walk up the destination propagation hierarchy.
So, for each new destination propagation node @m we use the previous copy of @last_source and the fact it's mounted on the previous propagation node @last_dest via @last_source->mnt_master->mnt_parent to determine what the master of the new copy of @last_source needs to be.
The goal is to find the _closest_ master that the new copy of the source mount tree we are about to create and mount on a slave @m in the destination propagation tree needs to pick. IOW, we want to find a suitable master in the propagation group.
As the propagation structure of the source mount propagation tree we create mirrors the propagation structure of the destination propagation tree we can find @m's closest master - i.e., a marked master - which is a peer in the closest peer group that @m receives propagation from. We store that closest master of @m in @p as before and record the slave to that master in @n
We then search for this master @p via @last_source by walking up the master hierarchy starting from the last copy of the source mount tree stored in @last_source that we created and mounted on the previous destination propagation node @m.
We will try to find the master by walking @last_source->mnt_master and by comparing @last_source->mnt_master->mnt_parent->mnt_master to @p. If we find @p then we can figure out what earlier copy of the source mount tree needs to be the master for the new copy of the source mount tree we're about to create and mount at the current destination propagation node @m.
If @last_source->mnt_master->mnt_parent and @n are peers then we know that the closest master they receive propagation from is @last_source->mnt_master->mnt_parent->mnt_master. If not then the closest immediate peer group that they receive propagation from must be one level higher up.
This builds on the earlier clarification at the beginning that all peers in a peer group which are slaves of other peer groups all point to the same ->mnt_master, i.e., appear on the same ->mnt_slave_list, of the closest peer group that they receive propagation from.
However, terminating the walk has corner cases.
If the closest marked master for a given destination node @m cannot be found by walking up the master hierarchy via @last_source->mnt_master then we need to terminate the walk when we encounter @source_mnt again.
This isn't an arbitrary termination. It simply means that the new copy of the source mount tree we're about to create has a copy of the source mount tree we created and mounted on a peer in @dest_mnt's peer group as its master. IOW, @source_mnt is the peer in the closest peer group that the new copy of the source mount tree receives propagation from.
We absolutely have to stop @source_mnt because @last_source->mnt_master either points outside the propagation hierarchy we're dealing with or it is NULL because @source_mnt isn't a shared-slave.
So continuing the walk past @source_mnt would cause a NULL dereference via @last_source->mnt_master->mnt_parent. And so we have to stop the walk when we encounter @source_mnt again.
One scenario where this can happen is when we first handled a series of slaves of @dest_mnt's peer group and then encounter peers in a new peer group that is a slave to @dest_mnt's peer group. We handle them and then we encounter another slave mount to @dest_mnt that is a pure slave to @dest_mnt's peer group. That pure slave will have a peer in @dest_mnt's peer group as its master. Consequently, the new copy of the source mount tree will need to have @source_mnt as it's master. So we walk the propagation hierarchy all the way up to @source_mnt based on @last_source->mnt_master.
So terminate on @source_mnt, easy peasy. Except, that the check misses something that the rest of the algorithm already handles.
If @dest_mnt has peers in it's peer group the peer loop in propagate_mnt():
for (n = next_peer(dest_mnt); n != dest_mnt; n = next_peer(n)) {
ret = propagate_one(n);
if (ret)
goto out;
}will consecutively update @last_source with each previous copy of the source mount tree we created and mounted at the previous peer in @dest_mnt's peer group. So after that loop terminates @last_source will point to whatever copy of the source mount tree was created and mounted on the last peer in @dest_mnt's peer group.
Furthermore, if there is even a single additional peer in @dest_mnt's peer group then @last_source will __not__ point to @source_mnt anymore. Because, as we mentioned above, @dest_mnt isn't even handled in this loop but directly in attach_recursive_mnt(). So it can't even accidently come last in that peer loop.
So the first time we handle a slave mount @m of @dest_mnt's peer group the copy of the source mount tree we create will make the __last copy of the source mount tree we created and mounted on the last peer in @dest_mnt's peer group the master of the new copy of the source mount tree we create and mount on the first slave of @dest_mnt's peer group__.
But this means that the termination condition that checks for @source_mnt is wrong. The @source_mnt cannot be found anymore by propagate_one(). Instead it will find the last copy of the source mount tree we created and mounted for the last peer of @dest_mnt's peer group again. And that is a peer of @source_mnt not @source_mnt itself.
IOW, we fail to terminate the loop correctly and ultimately dereference @last_source->mnt_master->mnt_parent. When @source_mnt's peer group isn't slave to another peer group then @last_source->mnt_master is NULL causing the splat below.
For example, assume @dest_mnt is a pure shared mount and has three peers in its peer group:
===================================================================================
mount-id mount-parent-id peer-group-id
===================================================================================
(@dest_mnt) mnt_master[216] 309 297 shared:216
\
(@source_mnt) mnt_master[218]: 609 609 shared:218(1) mnt_master[216]: 607 605 shared:216
\
(P1) mnt_master[218]: 624 607 shared:218(2) mnt_master[216]: 576 574 shared:216
\
(P2) mnt_master[218]: 625 576 shared:218(3) mnt_master[216]: 545 543 shared:216
\
(P3) mnt_master[218]: 626 545 shared:218After this sequence has been processed @last_source will point to (P3), the copy generated for the third peer in @dest_mnt's peer group we handled. So the copy of the source mount tree (P4) we create and mount on the first slave of @dest_mnt's peer group:
===================================================================================
mount-id mount-parent-id peer-group-id
===================================================================================
mnt_master[216] 309 297 shared:216
/
/
(S0) mnt_slave 483 481 master:216
\
\ (P3) mnt_master[218] 626 545 shared:218
\ /
\/
(P4) mnt_slave 627 483 master:218will pick the last copy of the source mount tree (P3) as master, not (S0).
When walking the propagation hierarchy via @last_source's master hierarchy we encounter (P3) but not (S0), i.e., @source_mnt.
We can fix this in multiple ways:
(1) By setting @last_source to @source_mnt after we processed the peers in @dest_mnt's peer group right after the peer loop in propagate_mnt().
(2) By changing the termination condition that relies on finding exactly @source_mnt to finding a peer of @source_mnt.
(3) By only moving @last_source when we actually venture into a new peer group or some clever variant thereof.
The first two options are minimally invasive and what we want as a fix. The third option is more intrusive but something we'd like to explore in the near future.
This passes all LTP tests and specifically the mount propagation testsuite part of it. It also holds up against all known reproducers of this issues.
Final words.
First, this is a clever but __worringly__ underdocumented algorithm. There isn't a single detailed comment to be found in next_group(), propagate_one() or anywhere else in that file for that matter. This has been a giant pain to understand and work through and a bug like this is insanely difficult to fix without a detailed understanding of what's happening. Let's not talk about the amount of time that was sunk into fixing this.
Second, all the cool kids with access to
unshare --mount --user --map-root --propagation=unchanged are going to have a lot of fun. IOW, triggerable by unprivileged users while namespace_lock() lock is held.
[ 115.848393] BUG: kernel NULL pointer dereference, address: 0000000000000010 [ 115.848967] #PF: supervisor read access in kernel mode [ 115.849386] #PF: error_code(0x0000) - not-present page [ 115.849803] PGD 0 P4D 0 [ 115.850012] Oops: 0000 [#1] PREEMPT SMP PTI [ 115.850354] CPU: 0 PID: 15591 Comm: mount Not tainted 6.1.0-rc7 #3 [ 115.850851] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 115.851510] RIP: 0010:propagate_one.part.0+0x7f/0x1a0 [ 115.851924] Code: 75 eb 4c 8b 05 c2 25 37 02 4c 89 ca 48 8b 4a 10 49 39 d0 74 1e 48 3b 81 e0 00 00 00 74 26 48 8b 92 e0 00 00 00 be 01 00 00 00 <48> 8b 4a 10 49 39 d0 75 e2 40 84 f6 74 38 4c 89 05 84 25 37 02 4d [ 115.853441] RSP: 0018:ffffb8d5443d7d50 EFLAGS: 00010282 [ 115.853865] RAX: ffff8e4d87c41c80 RBX: ffff8e4d88ded780 RCX: ffff8e4da4333a00 [ 115.854458] RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff8e4d88ded780 [ 115.855044] RBP: ffff8e4d88ded780 R08: ffff8e4da4338000 R09: ffff8e4da43388c0 [ 115.855693] R10: 0000000000000002 R11: ffffb8d540158000 R12: ffffb8d5443d7da8 [ 115.856304] R13: ffff8e4d88ded780 R14: 0000000000000000 R15: 0000000000000000 [ 115.856859] FS: 00007f92c90c9800(0000) GS:ffff8e4dfdc00000(0000) knlGS:0000000000000000 [ 115.857531] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 115.858006] CR2: 0000000000000010 CR3: 0000000022f4c002 CR4: 00000000000706f0 [ 115.858598] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 115.859393] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 115.860099] Call Trace: [ 115.860358] <TASK> [ 115.860535] propagate_mnt+0x14d/0x190 [ 115.860848] attach_recursive_mnt+0x274/0x3e0 [ 115.861212] path_mount+0x8c8/0xa60 [ 115.861503] __x64_sys_mount+0xf6/0x140 [ 115.861819] do_syscall_64+0x5b/0x80 [ 115.862117] ? do_faccessat+0x123/0x250 [ 115.862435] ? syscall_exit_to_user_mode+0x17/0x40 [ 115.862826] ? do_syscall_64+0x67/0x80 [ 115.863133] ? syscall_exit_to_user_mode+0x17/0x40 [ 115.863527] ? do_syscall_64+0x67/0x80 [ 115.863835] ? do_syscall_64+0x67/0x80 [ 115.864144] ? do_syscall_64+0x67/0x80 [ 115.864452] ? exc_page_fault+0x70/0x170 [ 115.864775] entry_SYSCALL_64_after_hwframe+0x63/0xcd [ 115.865187] RIP: 0033:0x7f92c92b0ebe [ 115.865480] Code: 48 8b 0d 75 4f 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 42 4f 0c 00 f7 d8 64 89 01 48 [ 115.866984] RSP: 002b:00007fff000aa728 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5 [ 115.867607] RAX: ffffffffffffffda RBX: 000055a77888d6b0 RCX: 00007f92c92b0ebe [ 115.868240] RDX: 000055a77888d8e0 RSI: 000055a77888e6e0 RDI: 000055a77888e620 [ 115.868823] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000001 [ 115.869403] R10: 0000000000001000 R11: 0000000000000246 R12: 000055a77888e620 [ 115.869994] R13: 000055a77888d8e0 R14: 00000000ffffffff R15: 00007f92c93e4076 [ 115.870581] </TASK> [ 115.870763] Modules linked in: nft_fib_inet nft_fib_ipv4
nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 ip_set rfkill nf_tables nfnetlink qrtr snd_intel8x0 sunrpc snd_ac97_codec ac97_bus snd_pcm snd_timer intel_rapl_msr intel_rapl_common snd vboxguest intel_powerclamp video rapl joydev soundcore i2c_piix4 wmi fuse zram xfs vmwgfx crct10dif_pclmul crc32_pclmul crc32c_intel polyval_clmulni polyval_generic drm_ttm_helper ttm e1000 ghash_clmulni_intel serio_raw ata_generic pata_acpi scsi_dh_rdac scsi_dh_emc scsi_dh_alua dm_multipath
[ 115.875288] CR2: 0000000000000010 [ 115.875641] ---[ end trace 0000000000000000 ]--- [ 115.876135] RIP: 0010:propagate_one.part.0+0x7f/0x1a0 [ 115.876551] Code: 75 eb 4c 8b 05 c2 25 37 02 4c 89 ca 48 8b 4a 10 49 39 d0 74 1e 48 3b 81 e0 00 00 00 74 26 48 8b 92 e0 00 00 00 be 01 00 00 00 <48> 8b 4a 10 49 39 d0 75 e2 40 84 f6 74 38 4c 89 05 84 25 37 02 4d [ 115.878086] RSP: 0018:ffffb8d5443d7d50 EFLAGS: 00010282 [ 115.878511] RAX: ffff8e4d87c41c80 RBX: ffff8e4d88ded780 RCX: ffff8e4da4333a00 [ 115.879128] RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff8e4d88ded780 [ 115.879715] RBP: ffff8e4d88ded780 R08: ffff8e4da4338000 R09: ffff8e4da43388c0 [ 115.880359] R10: 0000000000000002 R11: ffffb8d540158000 R12: ffffb8d5443d7da8 [ 115.880962] R13: ffff8e4d88ded780 R14: 0000000000000000 R15: 0000000000000000 [ 115.881548] FS: 00007f92c90c9800(0000) GS:ffff8e4dfdc00000(0000) knlGS:0000000000000000 [ 115.882234] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 115.882713] CR2: 0000000000000010 CR3: 0000000022f4c002 CR4: 00000000000706f0 [ 115.883314] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 115.883966] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
---
If there are no big objections I'll get this to Linus rather sooner than later.
--- fs/pnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/pnode.c +1 -1
@@ -244,7 +244,7 @@ static int propagate_one(struct mount *m } do { struct mount *parent = last_source->mnt_parent; - if (last_source == first_source) + if (peers(last_source, first_source)) break; done = parent->mnt_master == p; if (done && peers(n, parent))
Greg Kroah-Hartman
maintainerPATCH 470/658 md: fix a crash in mempool_free
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
commit 341097ee53573e06ab9fc675d96a052385b851fa upstream.
There's a crash in mempool_free when running the lvm test shell/lvchange-rebuild-raid.sh.
The reason for the crash is this:
* super_written calls atomic_dec_and_test(&mddev->pending_writes) and wake_up(&mddev->sb_wait). Then it calls rdev_dec_pending(rdev, mddev) and bio_put(bio).
* so, the process that waited on sb_wait and that is woken up is racing with bio_put(bio).
* if the process wins the race, it calls bioset_exit before bio_put(bio) is executed.
* bio_put(bio) attempts to free a bio into a destroyed bio set - causing a crash in mempool_free.
We fix this bug by moving bio_put before atomic_dec_and_test.
We also move rdev_dec_pending before atomic_dec_and_test as suggested by Neil Brown.
The function md_end_flush has a similar bug - we must call bio_put before we decrement the number of in-progress bios.
BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 11557f0067 P4D 11557f0067 PUD 0 Oops: 0002 [#1] PREEMPT SMP CPU: 0 PID: 73 Comm: kworker/0:1 Not tainted 6.1.0-rc3 #5 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 Workqueue: kdelayd flush_expired_bios [dm_delay] RIP: 0010:mempool_free+0x47/0x80 Code: 48 89 ef 5b 5d ff e0 f3 c3 48 89 f7 e8 32 45 3f 00 48 63 53 08 48 89 c6 3b 53 04 7d 2d 48 8b 43 10 8d 4a 01 48 89 df 89 4b 08 <48> 89 2c d0 e8 b0 45 3f 00 48 8d 7b 30 5b 5d 31 c9 ba 01 00 00 00 RSP: 0018:ffff88910036bda8 EFLAGS: 00010093 RAX: 0000000000000000 RBX: ffff8891037b65d8 RCX: 0000000000000001 RDX: 0000000000000000 RSI: 0000000000000202 RDI: ffff8891037b65d8 RBP: ffff8891447ba240 R08: 0000000000012908 R09: 00000000003d0900 R10: 0000000000000000 R11: 0000000000173544 R12: ffff889101a14000 R13: ffff8891562ac300 R14: ffff889102b41440 R15: ffffe8ffffa00d05 FS: 0000000000000000(0000) GS:ffff88942fa00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000001102e99000 CR4: 00000000000006b0 Call Trace: <TASK> clone_endio+0xf4/0x1c0 [dm_mod] clone_endio+0xf4/0x1c0 [dm_mod] __submit_bio+0x76/0x120 submit_bio_noacct_nocheck+0xb6/0x2a0 flush_expired_bios+0x28/0x2f [dm_delay] process_one_work+0x1b4/0x300 worker_thread+0x45/0x3e0 ? rescuer_thread+0x380/0x380 kthread+0xc2/0x100 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x1f/0x30 </TASK> Modules linked in: brd dm_delay dm_raid dm_mod af_packet uvesafb cfbfillrect cfbimgblt cn cfbcopyarea fb font fbdev tun autofs4 binfmt_misc configfs ipv6 virtio_rng virtio_balloon rng_core virtio_net pcspkr net_failover failover qemu_fw_cfg button mousedev raid10 raid456 libcrc32c async_raid6_recov async_memcpy async_pq raid6_pq async_xor xor async_tx raid1 raid0 md_mod sd_mod t10_pi crc64_rocksoft crc64 virtio_scsi scsi_mod evdev psmouse bsg scsi_common [last unloaded: brd] CR2: 0000000000000000 ---[ end trace 0000000000000000 ]---
--- drivers/md/md.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/md/md.c +6 -3
@@ -481,13 +481,14 @@ static void md_end_flush(struct bio *biostruct md_rdev *rdev = bio->bi_private;struct mddev *mddev = rdev->mddev; +bio_put (bio); +rdev_dec_pending (rdev, mddev);if (atomic_dec_and_test (&mddev->flush_pending)) {/* The pre-request flush has finished */ queue_work (md_wq, &mddev->flush_work); } -bio_put (bio); }static void md_submit_flush_data (struct work_struct *ws);
@@ -885,10 +886,12 @@ static void super_written(struct bio *bi }else clear_bit (LastDev, &rdev->flags); +bio_put (bio); + +rdev_dec_pending (rdev, mddev); +if (atomic_dec_and_test (&mddev->pending_writes))wake_up (&mddev->sb_wait); -rdev_dec_pending (rdev, mddev); -bio_put (bio); } void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
Greg Kroah-Hartman
maintainerPATCH 471/658 mm, compaction: fix fast_isolate_around() to stay within boundaries
In reply to Greg Kroah-HartmanFrom: NARIBAYASHI Akira <[email protected]>
commit be21b32afe470c5ae98e27e49201158a47032942 upstream.
Depending on the memory configuration, isolate_freepages_block() may scan pages out of the target range and causes panic.
Panic can occur on systems with multiple zones in a single pageblock.
The reason it is rare is that it only happens in special configurations. Depending on how many similar systems there are, it may be a good idea to fix this problem for older kernels as well.
The problem is that pfn as argument of fast_isolate_around() could be out of the target range. Therefore we should consider the case where pfn < start_pfn, and also the case where end_pfn < pfn.
This problem should have been addressd by the commit 6e2b7044c199 ("mm,
compaction: make fast_isolate_freepages() stay within zone") but there was an oversight.
Case1: pfn < start_pfn
<at memory compaction for node Y>
| node X's zone | node Y's zone
+-----------------+------------------------------...
pageblock ^ ^ ^
+-----------+-----------+-----------+-----------+...
^ ^ ^
^ ^ end_pfn
^ start_pfn = cc->zone->zone_start_pfn
pfn
<---------> scanned range by "Scan After" Case2: end_pfn < pfn
<at memory compaction for node X>
| node X's zone | node Y's zone
+-----------------+------------------------------...
pageblock ^ ^ ^
+-----------+-----------+-----------+-----------+...
^ ^ ^
^ ^ pfn
^ end_pfn
start_pfn
<---------> scanned range by "Scan Before"It seems that there is no good reason to skip nr_isolated pages just after given pfn. So let perform simple scan from start to end instead of dividing the scan into "Before" and "After".
--- mm/compaction.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
mm/compaction.c +5 -13
@@ -1219,7 +1219,7 @@ move_freelist_tail(struct list_head *fre }static void -fast_isolate_around (struct compact_control *cc,unsigned long pfn,unsigned long nr_isolated) +fast_isolate_around (struct compact_control *cc,unsigned long pfn) {unsigned long start_pfn, end_pfn;struct page *page =pfn_to_page (pfn);
@@ -1236,21 +1236,13 @@ fast_isolate_around(struct compact_contr start_pfn =pageblock_start_pfn (pfn); end_pfn =min (pageblock_end_pfn (pfn),zone_end_pfn (cc->zone)) -1 ; -/* Scan before */ -if (start_pfn != pfn) { -isolate_freepages_block (cc, &start_pfn, pfn, &cc->freepages,1 , false); -if (cc->nr_freepages >= cc->nr_migratepages) -return ; - } - -/* Scan after */ - start_pfn = pfn + nr_isolated; -if (start_pfn < end_pfn) -isolate_freepages_block (cc, &start_pfn, end_pfn, &cc->freepages,1 , false); +isolate_freepages_block (cc, &start_pfn, end_pfn, &cc->freepages,1 , false);/* Skip this pageblock in the future as it's full or nearly full */ if (cc->nr_freepages < cc->nr_migratepages)set_pageblock_skip (page); + +return ; }/* Search orders in round-robin fashion */
@@ -1422,7 +1414,7 @@ fast_isolate_freepages(struct compact_coreturn cc->free_pfn; low_pfn =page_to_pfn (page); -fast_isolate_around (cc, low_pfn, nr_isolated); +fast_isolate_around (cc, low_pfn);return low_pfn; }
Greg Kroah-Hartman
maintainerPATCH 472/658 f2fs: should put a page when checking the summary info
In reply to Greg Kroah-HartmanFrom: Pavel Machek <[email protected]>
commit c3db3c2fd9992c08f49aa93752d3c103c3a4f6aa upstream.
The commit introduces another bug.
--- fs/f2fs/gc.c | 1 + 1 file changed, 1 insertion(+)
fs/f2fs/gc.c +1 -0
@@ -643,6 +643,7 @@ static bool is_alive(struct f2fs_sb_infoif (ofs_in_node >= max_addrs) {f2fs_err (sbi,"Inconsistent ofs_in_node:%u in summary, ino:%u, nid:%u, max:%u" , ofs_in_node, dni->ino, dni->nid, max_addrs); +f2fs_put_page (node_page,1 );return false; }
Greg Kroah-Hartman
maintainerPATCH 473/658 mmc: vub300: fix warning - do not call blocking ops when !TASK_RUNNING
In reply to Greg Kroah-HartmanFrom: Deren Wu <[email protected]>
commit 4a44cd249604e29e7b90ae796d7692f5773dd348 upstream.
vub300_enable_sdio_irq() works with mutex and need TASK_RUNNING here. Ensure that we mark current as TASK_RUNNING for sleepable context.
[ 77.554641] do not call blocking ops when !TASK_RUNNING; state=1 set at [<ffffffff92a72c1d>] sdio_irq_thread+0x17d/0x5b0 [ 77.554652] WARNING: CPU: 2 PID: 1983 at kernel/sched/core.c:9813 __might_sleep+0x116/0x160 [ 77.554905] CPU: 2 PID: 1983 Comm: ksdioirqd/mmc1 Tainted: G OE 6.1.0-rc5 #1 [ 77.554910] Hardware name: Intel(R) Client Systems NUC8i7BEH/NUC8BEB, BIOS BECFL357.86A.0081.2020.0504.1834 05/04/2020 [ 77.554912] RIP: 0010:__might_sleep+0x116/0x160 [ 77.554920] RSP: 0018:ffff888107b7fdb8 EFLAGS: 00010282 [ 77.554923] RAX: 0000000000000000 RBX: ffff888118c1b740 RCX: 0000000000000000 [ 77.554926] RDX: 0000000000000001 RSI: 0000000000000004 RDI: ffffed1020f6ffa9 [ 77.554928] RBP: ffff888107b7fde0 R08: 0000000000000001 R09: ffffed1043ea60ba [ 77.554930] R10: ffff88821f5305cb R11: ffffed1043ea60b9 R12: ffffffff93aa3a60 [ 77.554932] R13: 000000000000011b R14: 7fffffffffffffff R15: ffffffffc0558660 [ 77.554934] FS: 0000000000000000(0000) GS:ffff88821f500000(0000) knlGS:0000000000000000 [ 77.554937] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 77.554939] CR2: 00007f8a44010d68 CR3: 000000024421a003 CR4: 00000000003706e0 [ 77.554942] Call Trace: [ 77.554944] <TASK> [ 77.554952] mutex_lock+0x78/0xf0 [ 77.554973] vub300_enable_sdio_irq+0x103/0x3c0 [vub300] [ 77.554981] sdio_irq_thread+0x25c/0x5b0 [ 77.555006] kthread+0x2b8/0x370 [ 77.555017] ret_from_fork+0x1f/0x30 [ 77.555023] </TASK> [ 77.555025] ---[ end trace 0000000000000000 ]---
--- drivers/mmc/host/vub300.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mmc/host/vub300.c +2 -0
@@ -2049,6 +2049,7 @@ static void vub300_enable_sdio_irq(strucreturn ;kref_get (&vub300->kref);if (enable) { +set_current_state (TASK_RUNNING );mutex_lock (&vub300->irq_mutex);if (vub300->irqs_queued) { vub300->irqs_queued -=1 ;
@@ -2064,6 +2065,7 @@ static void vub300_enable_sdio_irq(strucvub300_queue_poll_work (vub300,0 ); }mutex_unlock (&vub300->irq_mutex); +set_current_state (TASK_INTERRUPTIBLE ); }else { vub300->irq_enabled =0 ; }
Greg Kroah-Hartman
maintainerPATCH 474/658 tpm: tpm_crb: Add the missed acpi_put_table() to fix memory leak
In reply to Greg Kroah-HartmanFrom: Hanjun Guo <[email protected]>
commit 37e90c374dd11cf4919c51e847c6d6ced0abc555 upstream.
In crb_acpi_add(), we get the TPM2 table to retrieve information like start method, and then assign them to the priv data, so the TPM2 table is not used after the init, should be freed, call acpi_put_table() to fix the memory leak.
--- drivers/char/tpm/tpm_crb.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/char/tpm/tpm_crb.c +20 -9
@@ -676,12 +676,16 @@ static int crb_acpi_add(struct acpi_devi/* Should the FIFO driver handle this? */ sm = buf->start_method; -if (sm ==ACPI_TPM2_MEMORY_MAPPED ) -return -ENODEV ; +if (sm ==ACPI_TPM2_MEMORY_MAPPED ) { + rc = -ENODEV ; + goto out; + } priv =devm_kzalloc (dev,sizeof (struct crb_priv ),GFP_KERNEL ); -if (!priv) -return -ENOMEM ; +if (!priv) { + rc = -ENOMEM ; + goto out; + }if (sm ==ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC ) {if (buf->header.length < (sizeof (*buf) +sizeof (*crb_smc))) {
@@ -689,7 +693,8 @@ static int crb_acpi_add(struct acpi_deviFW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n" , buf->header.length, ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC); -return -EINVAL ; + rc = -EINVAL ; + goto out; } crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, sizeof(*buf)); priv->smc_func_id = crb_smc->smc_func_id;
@@ -700,17 +705,23 @@ static int crb_acpi_add(struct acpi_devi rc =crb_map_io (device, priv, buf);if (rc) -return rc; + goto out; chip =tpmm_chip_alloc (dev, &tpm_crb); -if (IS_ERR (chip)) -return PTR_ERR (chip); +if (IS_ERR (chip)) { + rc =PTR_ERR (chip); + goto out; + }dev_set_drvdata (&chip->dev, priv); chip->acpi_dev_handle = device->handle; chip->flags =TPM_CHIP_FLAG_TPM2 ; -return tpm_chip_register (chip); + rc =tpm_chip_register (chip); + +out: +acpi_put_table ((struct acpi_table_header *)buf); +return rc; }static int crb_acpi_remove (struct acpi_device *device)
Greg Kroah-Hartman
maintainerPATCH 475/658 tpm: tpm_tis: Add the missed acpi_put_table() to fix memory leak
In reply to Greg Kroah-HartmanFrom: Hanjun Guo <[email protected]>
commit db9622f762104459ff87ecdf885cc42c18053fd9 upstream.
In check_acpi_tpm2(), we get the TPM2 table just to make sure the table is there, not used after the init, so the acpi_put_table() should be added to release the ACPI memory.
--- drivers/char/tpm/tpm_tis.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm_tis.c +5 -4
@@ -125,6 +125,7 @@ static int check_acpi_tpm2(struct deviceconst struct acpi_device_id *aid =acpi_match_device (tpm_acpi_tbl, dev);struct acpi_table_tpm2 *tbl;acpi_status st; +int ret =0 ;if (!aid || aid->driver_data !=DEVICE_IS_TPM2 )return 0 ;
@@ -132,8 +133,7 @@ static int check_acpi_tpm2(struct device/* If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2 * table is mandatory */ - st = -acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **)&tbl); + st =acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **)&tbl);if (ACPI_FAILURE (st) || tbl->header.length <sizeof (*tbl)) {dev_err (dev,FW_BUG "failed to get TPM2 ACPI table\n" );return -EINVAL ;
@@ -141,9 +141,10 @@ static int check_acpi_tpm2(struct device/* The tpm2_crb driver handles this device */ if (tbl->start_method !=ACPI_TPM2_MEMORY_MAPPED ) -return -ENODEV ; + ret = -ENODEV ; - return 0; +acpi_put_table ((struct acpi_table_header *)tbl); + return ret; }#else static int check_acpi_tpm2 (struct device *dev)
Greg Kroah-Hartman
maintainerPATCH 476/658 SUNRPC: Dont leak netobj memory when gss_read_proxy_verf() fails
In reply to Greg Kroah-HartmanFrom: Chuck Lever <[email protected]>
commit da522b5fe1a5f8b7c20a0023e87b52a150e53bf5 upstream.
--- net/sunrpc/auth_gss/svcauth_gss.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +7 -2
@@ -1104,18 +1104,23 @@ static int gss_read_proxy_verf(struct svreturn res; inlen =svc_getnl (argv); -if (inlen > (argv->iov_len + rqstp->rq_arg.page_len)) +if (inlen > (argv->iov_len + rqstp->rq_arg.page_len)) { +kfree (in_handle->data);return SVC_DENIED ; + } pages =DIV_ROUND_UP (inlen,PAGE_SIZE ); in_token->pages =kcalloc (pages,sizeof (struct page *),GFP_KERNEL ); -if (!in_token->pages) +if (!in_token->pages) { +kfree (in_handle->data);return SVC_DENIED ; + } in_token->page_base =0 ; in_token->page_len = inlen;for (i =0 ; i < pages; i++) { in_token->pages[i] =alloc_page (GFP_KERNEL );if (!in_token->pages[i]) { +kfree (in_handle->data);gss_free_in_token_pages (in_token);return SVC_DENIED ; }
Greg Kroah-Hartman
maintainerPATCH 477/658 net/af_packet: add VLAN support for AF_PACKET SOCK_RAW GSO
In reply to Greg Kroah-HartmanFrom: Hangbin Liu <[email protected]>
commit dfed913e8b55a0c2c4906f1242fd38fd9a116e49 upstream.
Currently, the kernel drops GSO VLAN tagged packet if it's created with socket(AF_PACKET, SOCK_RAW, 0) plus virtio_net_hdr.
The reason is AF_PACKET doesn't adjust the skb network header if there is a VLAN tag. Then after virtio_net_hdr_set_proto() called, the skb->protocol will be set to ETH_P_IP/IPv6. And in later inet/ipv6_gso_segment() the skb is dropped as network header position is invalid.
Let's handle VLAN packets by adjusting network header position in packet_parse_headers(). The adjustment is safe and does not affect the later xmit as tap device also did that.
In packet_snd(), packet_parse_headers() need to be moved before calling virtio_net_hdr_set_proto(), so we can set correct skb->protocol and network header first.
There is no need to update tpacket_snd() as it calls packet_parse_headers() in tpacket_fill_skb(), which is already before calling virtio_net_hdr_* functions.
skb->no_fcs setting is also moved upper to make all skb settings together and keep consistency with function packet_sendmsg_spkt().
--- net/packet/af_packet.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
net/packet/af_packet.c +13 -5
@@ -1864,12 +1864,20 @@ oom:static void packet_parse_headers (struct sk_buff *skb,struct socket *sock) { +int depth; +if ((!skb->protocol || skb->protocol ==htons (ETH_P_ALL )) && sock->type ==SOCK_RAW ) {skb_reset_mac_header (skb); skb->protocol =dev_parse_header_protocol (skb); } +/* Move network header to the right position for VLAN tagged packets */ +if (likely (skb->dev->type ==ARPHRD_ETHER ) && +eth_type_vlan (skb->protocol) && +__vlan_get_protocol (skb, skb->protocol, &depth) !=0 ) +skb_set_network_header (skb, depth); +skb_probe_transport_header (skb); }
@@ -2979,6 +2987,11 @@ static int packet_snd(struct socket *soc skb->mark = sockc.mark; skb->tstamp = sockc.transmit_time; +if (unlikely (extra_len ==4 )) + skb->no_fcs =1 ; + +packet_parse_headers (skb, sock); +if (has_vnet_hdr) { err =virtio_net_hdr_to_skb (skb, &vnet_hdr,vio_le ());if (err)
@@ -2987,11 +3000,6 @@ static int packet_snd(struct socket *socvirtio_net_hdr_set_proto (skb, &vnet_hdr); } -packet_parse_headers (skb, sock); - -if (unlikely (extra_len ==4 )) - skb->no_fcs =1 ; - err = po->xmit (skb);if (unlikely (err !=0 )) {if (err >0 )
Greg Kroah-Hartman
maintainerPATCH 478/658 net/af_packet: make sure to pull mac header
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
commit e9d3f80935b6607dcdc5682b00b1d4b28e0a0c5d upstream.
GSO assumes skb->head contains link layer headers.
tun device in some case can provide base 14 bytes, regardless of VLAN being used or not.
After blamed commit, we can end up setting a network header offset of 18+, we better pull the missing bytes to avoid a posible crash in GSO.
syzbot report was:
kernel BUG at include/linux/skbuff.h:2699!
invalid opcode: 0000 [#1] PREEMPT SMP KASAN
CPU: 1 PID: 3601 Comm: syz-executor210 Not tainted 5.18.0-syzkaller-11338-g2c5ca23f7414 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:__skb_pull include/linux/skbuff.h:2699 [inline] RIP: 0010:skb_mac_gso_segment+0x48f/0x530 net/core/gro.c:136 Code: 00 48 c7 c7 00 96 d4 8a c6 05 cb d3 45 06 01 e8 26 bb d0 01 e9 2f fd ff ff 49 c7 c4 ea ff ff ff e9 f1 fe ff ff e8 91 84 19 fa <0f> 0b 48 89 df e8 97 44 66 fa e9 7f fd ff ff e8 ad 44 66 fa e9 48 RSP: 0018:ffffc90002e2f4b8 EFLAGS: 00010293 RAX: 0000000000000000 RBX: 0000000000000012 RCX: 0000000000000000 RDX: ffff88805bb58000 RSI: ffffffff8760ed0f RDI: 0000000000000004 RBP: 0000000000005dbc R08: 0000000000000004 R09: 0000000000000fe0 R10: 0000000000000fe4 R11: 0000000000000000 R12: 0000000000000fe0 R13: ffff88807194d780 R14: 1ffff920005c5e9b R15: 0000000000000012 FS: 000055555730f300(0000) GS:ffff8880b9d00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000200015c0 CR3: 0000000071ff8000 CR4: 0000000000350ee0 Call Trace: <TASK> __skb_gso_segment+0x327/0x6e0 net/core/dev.c:3411 skb_gso_segment include/linux/netdevice.h:4749 [inline] validate_xmit_skb+0x6bc/0xf10 net/core/dev.c:3669 validate_xmit_skb_list+0xbc/0x120 net/core/dev.c:3719 sch_direct_xmit+0x3d1/0xbe0 net/sched/sch_generic.c:327 __dev_xmit_skb net/core/dev.c:3815 [inline] __dev_queue_xmit+0x14a1/0x3a00 net/core/dev.c:4219 packet_snd net/packet/af_packet.c:3071 [inline] packet_sendmsg+0x21cb/0x5550 net/packet/af_packet.c:3102 sock_sendmsg_nosec net/socket.c:714 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:734 ____sys_sendmsg+0x6eb/0x810 net/socket.c:2492 ___sys_sendmsg+0xf3/0x170 net/socket.c:2546 __sys_sendmsg net/socket.c:2575 [inline] __do_sys_sendmsg net/socket.c:2584 [inline] __se_sys_sendmsg net/socket.c:2582 [inline] __x64_sys_sendmsg+0x132/0x220 net/socket.c:2582 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x46/0xb0 RIP: 0033:0x7f4b95da06c9 Code: 28 c3 e8 4a 15 00 00 66 2e 0f 1f 84 00 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd7defc4c8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007ffd7defc4f0 RCX: 00007f4b95da06c9 RDX: 0000000000000000 RSI: 0000000020000140 RDI: 0000000000000003 RBP: 0000000000000003 R08: bb1414ac00000050 R09: bb1414ac00000050 R10: 0000000000000004 R11: 0000000000000246 R12: 0000000000000000 R13: 00007ffd7defc4e0 R14: 00007ffd7defc4d8 R15: 00007ffd7defc4d4 </TASK>
--- net/packet/af_packet.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/packet/af_packet.c +4 -2
@@ -1875,8 +1875,10 @@ static void packet_parse_headers(struct/* Move network header to the right position for VLAN tagged packets */ if (likely (skb->dev->type ==ARPHRD_ETHER ) &ð_type_vlan (skb->protocol) && -__vlan_get_protocol (skb, skb->protocol, &depth) !=0 ) -skb_set_network_header (skb, depth); +__vlan_get_protocol (skb, skb->protocol, &depth) !=0 ) { +if (pskb_may_pull (skb, depth)) +skb_set_network_header (skb, depth); + }skb_probe_transport_header (skb); }
Greg Kroah-Hartman
maintainerPATCH 479/658 media: stv0288: use explicitly signed char
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit 7392134428c92a4cb541bd5c8f4f5c8d2e88364d upstream.
With char becoming unsigned by default, and with char alone being ambiguous and based on architecture, signed chars need to be marked explicitly as such. Use s8 and u8 types here, since that's what surrounding code does. This fixes:
drivers/media/dvb-frontends/stv0288.c:471 stv0288_set_frontend() warn: assigning (-9) to unsigned variable 'tm' drivers/media/dvb-frontends/stv0288.c:471 stv0288_set_frontend() warn: we never enter this loop
--- drivers/media/dvb-frontends/stv0288.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/dvb-frontends/stv0288.c +2 -3
@@ -440,9 +440,8 @@ static int stv0288_set_frontend(struct dstruct stv0288_state *state = fe->demodulator_priv;struct dtv_frontend_properties *c = &fe->dtv_property_cache; -char tm; -unsigned char tda[3 ]; -u8 reg, time_out =0 ; +u8 tda[3 ], reg, time_out =0 ; +s8 tm;dprintk ("%s : FE_SET_FRONTEND\n" , __func__);
Greg Kroah-Hartman
maintainerPATCH 480/658 soc: qcom: Select REMAP_MMIO for LLCC driver
In reply to Greg Kroah-HartmanFrom: Manivannan Sadhasivam <[email protected]>
commit 5d2fe2d7b616b8baa18348ead857b504fc2de336 upstream.
LLCC driver uses REGMAP_MMIO for accessing the hardware registers. So select the dependency in Kconfig. Without this, there will be errors while building the driver with COMPILE_TEST only:
ERROR: modpost: "__devm_regmap_init_mmio_clk" [drivers/soc/qcom/llcc-qcom.ko] undefined! make[1]: *** [scripts/Makefile.modpost:126: Module.symvers] Error 1
make: *** [Makefile:1944: modpost] Error 2
--- drivers/soc/qcom/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/soc/qcom/Kconfig +1 -0
@@ -56,6 +56,7 @@ config QCOM_GSBI config QCOM_LLCC tristate "Qualcomm Technologies, Inc. LLCC driver" depends on ARCH_QCOM || COMPILE_TEST + select REGMAP_MMIO help Qualcomm Technologies, Inc. platform specific Last Level Cache Controller(LLCC) driver for platforms such as,
Greg Kroah-Hartman
maintainerPATCH 481/658 kest.pl: Fix grub2 menu handling for rebooting
In reply to Greg Kroah-HartmanFrom: Steven Rostedt <[email protected]>
commit 26df05a8c1420ad3de314fdd407e7fc2058cc7aa upstream.
grub2 has submenus where to use grub-reboot, it requires:
grub-reboot X>Y
where X is the main index and Y is the submenu. Thus if you have:
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux ...
[...]
}
submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option ...
menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64' --class debian --class gnu-linux ...
[...]
}
menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64 (recovery mode)' --class debian --class gnu-linux ...
[...]
}
menuentry 'Debian GNU/Linux, with Linux test' --class debian --class gnu-linux ...
[...]
}And wanted to boot to the "Linux test" kernel, you need to run:
# grub-reboot 1>2
As 1 is the second top menu (the submenu) and 2 is the third of the sub menu entries.
Have the grub.cfg parsing for grub2 handle such cases.
--- tools/testing/ktest/ktest.pl | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
tools/testing/ktest/ktest.pl +15 -5
@@ -1881,7 +1881,7 @@ sub run_scp_mod { sub _get_grub_index { - my ($command, $target, $skip) = @_; + my ($command, $target, $skip, $submenu) = @_; return if (defined($grub_number) && defined($last_grub_menu) && $last_grub_menu eq $grub_menu && defined($last_machine) &&
@@ -1898,11 +1898,16 @@ sub _get_grub_index { my $found = 0; + my $submenu_number = 0; + while (<IN>) { if (/$target/) { $grub_number++; $found = 1; last; + } elsif (defined($submenu) && /$submenu/) { + $submenu_number++; + $grub_number = -1; } elsif (/$skip/) { $grub_number++; }
@@ -1911,6 +1916,9 @@ sub _get_grub_index { dodie "Could not find '$grub_menu' through $command on $machine" if (!$found); + if ($submenu_number > 0) { + $grub_number = "$submenu_number>$grub_number"; + } doprint "$grub_number\n"; $last_grub_menu = $grub_menu; $last_machine = $machine;
@@ -1921,6 +1929,7 @@ sub get_grub_index { my $command; my $target; my $skip; + my $submenu; my $grub_menu_qt; if ($reboot_type !~ /^grub/) {
@@ -1935,8 +1944,9 @@ sub get_grub_index { $skip = '^\s*title\s'; } elsif ($reboot_type eq "grub2") { $command = "cat $grub_file"; - $target = '^menuentry.*' . $grub_menu_qt; - $skip = '^menuentry\s|^submenu\s'; + $target = '^\s*menuentry.*' . $grub_menu_qt; + $skip = '^\s*menuentry'; + $submenu = '^\s*submenu\s'; } elsif ($reboot_type eq "grub2bls") { $command = $grub_bls_get; $target = '^title=.*' . $grub_menu_qt;
@@ -1945,7 +1955,7 @@ sub get_grub_index { return; } - _get_grub_index($command, $target, $skip); + _get_grub_index($command, $target, $skip, $submenu); } sub wait_for_input
@@ -2009,7 +2019,7 @@ sub reboot_to { if ($reboot_type eq "grub") { run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'"; } elsif (($reboot_type eq "grub2") or ($reboot_type eq "grub2bls")) { - run_ssh "$grub_reboot $grub_number"; + run_ssh "$grub_reboot \"'$grub_number'\""; } elsif ($reboot_type eq "syslinux") { run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path"; } elsif (defined $reboot_script) {
Greg Kroah-Hartman
maintainerPATCH 482/658 ktest.pl minconfig: Unset configs instead of just removing them
In reply to Greg Kroah-HartmanFrom: Steven Rostedt <[email protected]>
commit ef784eebb56425eed6e9b16e7d47e5c00dcf9c38 upstream.
After a full run of a make_min_config test, I noticed there were a lot of CONFIGs still enabled that really should not be. Looking at them, I noticed they were all defined as "default y". The issue is that the test simple removes the config and re-runs make oldconfig, which enables it again because it is set to default 'y'. Instead, explicitly disable the config with writing "# CONFIG_FOO is not set" to the file to keep it from being set again.
With this change, one of my box's minconfigs went from 768 configs set, down to 521 configs set.
--- tools/testing/ktest/ktest.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/ktest/ktest.pl +2 -1
@@ -3736,9 +3736,10 @@ sub test_this_config { # .config to make sure it is missing the config that # we had before my %configs = %min_configs; - delete $configs{$config}; + $configs{$config} = "# $config is not set"; make_new_config ((values %configs), (values %keep_configs)); make_oldconfig; + delete $configs{$config}; undef %configs; assign_configs \%configs, $output_config;
Greg Kroah-Hartman
maintainerPATCH 483/658 mmc: sdhci-sprd: Disable CLK_AUTO when the clock is less than 400K
In reply to Greg Kroah-HartmanFrom: Wenchao Chen <[email protected]>
commit ff874dbc4f868af128b412a9bd92637103cf11d7 upstream.
When the clock is less than 400K, some SD cards fail to initialize because CLK_AUTO is enabled.
--- drivers/mmc/host/sdhci-sprd.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/mmc/host/sdhci-sprd.c +9 -7
@@ -223,13 +223,15 @@ static inline void _sdhci_sprd_set_clock div = ((div &0x300 ) >>2 ) | ((div &0xFF ) <<8 );sdhci_enable_clk (host, div); -/* enable auto gate sdhc_enable_auto_gate */ - val =sdhci_readl (host,SDHCI_SPRD_REG_32_BUSY_POSI ); - mask =SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | -SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN ; -if (mask != (val & mask)) { - val |= mask; -sdhci_writel (host, val,SDHCI_SPRD_REG_32_BUSY_POSI ); +/* Enable CLK_AUTO when the clock is greater than 400K. */ +if (clk >400000 ) { + val =sdhci_readl (host,SDHCI_SPRD_REG_32_BUSY_POSI ); + mask =SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN | +SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN ; +if (mask != (val & mask)) { + val |= mask; +sdhci_writel (host, val,SDHCI_SPRD_REG_32_BUSY_POSI ); + } } }
Greg Kroah-Hartman
maintainerPATCH 484/658 btrfs: fix resolving backrefs for inline extent followed by prealloc
In reply to Greg Kroah-HartmanFrom: Boris Burkov <[email protected]>
commit 560840afc3e63bbe5d9c5ef6b2ecf8f3589adff6 upstream.
If a file consists of an inline extent followed by a regular or prealloc extent, then a legitimate attempt to resolve a logical address in the non-inline region will result in add_all_parents reading the invalid offset field of the inline extent. If the inline extent item is placed in the leaf eb s.t. it is the first item, attempting to access the offset field will not only be meaningless, it will go past the end of the eb and cause this panic:
[17.626048] BTRFS warning (device dm-2): bad eb member end: ptr 0x3fd4 start 30834688 member offset 16377 size 8 [17.631693] general protection fault, probably for non-canonical address 0x5088000000000: 0000 [#1] SMP PTI [17.635041] CPU: 2 PID: 1267 Comm: btrfs Not tainted 5.12.0-07246-g75175d5adc74-dirty #199 [17.637969] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 [17.641995] RIP: 0010:btrfs_get_64+0xe7/0x110 [17.649890] RSP: 0018:ffffc90001f73a08 EFLAGS: 00010202 [17.651652] RAX: 0000000000000001 RBX: ffff88810c42d000 RCX: 0000000000000000 [17.653921] RDX: 0005088000000000 RSI: ffffc90001f73a0f RDI: 0000000000000001 [17.656174] RBP: 0000000000000ff9 R08: 0000000000000007 R09: c0000000fffeffff [17.658441] R10: ffffc90001f73790 R11: ffffc90001f73788 R12: ffff888106afe918 [17.661070] R13: 0000000000003fd4 R14: 0000000000003f6f R15: cdcdcdcdcdcdcdcd [17.663617] FS: 00007f64e7627d80(0000) GS:ffff888237c80000(0000) knlGS:0000000000000000 [17.666525] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [17.668664] CR2: 000055d4a39152e8 CR3: 000000010c596002 CR4: 0000000000770ee0 [17.671253] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [17.673634] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [17.676034] PKRU: 55555554 [17.677004] Call Trace: [17.677877] add_all_parents+0x276/0x480 [17.679325] find_parent_nodes+0xfae/0x1590 [17.680771] btrfs_find_all_leafs+0x5e/0xa0 [17.682217] iterate_extent_inodes+0xce/0x260 [17.683809] ? btrfs_inode_flags_to_xflags+0x50/0x50 [17.685597] ? iterate_inodes_from_logical+0xa1/0xd0 [17.687404] iterate_inodes_from_logical+0xa1/0xd0 [17.689121] ? btrfs_inode_flags_to_xflags+0x50/0x50 [17.691010] btrfs_ioctl_logical_to_ino+0x131/0x190 [17.692946] btrfs_ioctl+0x104a/0x2f60 [17.694384] ? selinux_file_ioctl+0x182/0x220 [17.695995] ? __x64_sys_ioctl+0x84/0xc0 [17.697394] __x64_sys_ioctl+0x84/0xc0 [17.698697] do_syscall_64+0x33/0x40 [17.700017] entry_SYSCALL_64_after_hwframe+0x44/0xae [17.701753] RIP: 0033:0x7f64e72761b7 [17.709355] RSP: 002b:00007ffefb067f58 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [17.712088] RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f64e72761b7 [17.714667] RDX: 00007ffefb067fb0 RSI: 00000000c0389424 RDI: 0000000000000003 [17.717386] RBP: 00007ffefb06d188 R08: 000055d4a390d2b0 R09: 00007f64e7340a60 [17.719938] R10: 0000000000000231 R11: 0000000000000246 R12: 0000000000000001 [17.722383] R13: 0000000000000000 R14: 00000000c0389424 R15: 000055d4a38fd2a0 [17.724839] Modules linked in:
Fix the bug by detecting the inline extent item in add_all_parents and skipping to the next extent item.
--- fs/btrfs/backref.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/btrfs/backref.c +4 -0
@@ -431,6 +431,7 @@ static int add_all_parents(struct btrfs_u64 wanted_disk_byte = ref->wanted_disk_byte;u64 count =0 ;u64 data_offset; +u8 type;if (level !=0 ) { eb = path->nodes[level];
@@ -485,6 +486,9 @@ static int add_all_parents(struct btrfs_continue ; } fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item); + type =btrfs_file_extent_type (eb, fi); +if (type ==BTRFS_FILE_EXTENT_INLINE ) + goto next; disk_byte =btrfs_file_extent_disk_bytenr (eb, fi); data_offset =btrfs_file_extent_offset (eb, fi);
Greg Kroah-Hartman
maintainerPATCH 485/658 ARM: ux500: do not directly dereference __iomem
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit 65b0e307a1a9193571db12910f382f84195a3d29 upstream.
Sparse reports that calling add_device_randomness() on uid is a violation of address spaces. And indeed the next usage uses readl() properly, but that was left out when passing it toadd_device_ randomness(). So instead copy the whole thing to the stack first.
--- drivers/soc/ux500/ux500-soc-id.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/soc/ux500/ux500-soc-id.c +4 -6
@@ -159,20 +159,18 @@ static ssize_t ux500_get_process(structstatic const char *db8500_read_soc_id (struct device_node *backupram) {void __iomem *base; -void __iomem *uid;const char *retstr; +u32 uid[5 ]; base =of_iomap (backupram,0 );if (!base)return NULL ; - uid = base +0x1fc0 ; +memcpy_fromio (uid, base +0x1fc0 ,sizeof (uid));/* Throw these device-specific numbers into the entropy pool */ -add_device_randomness (uid,0x14 ); +add_device_randomness (uid,sizeof (uid)); retstr =kasprintf (GFP_KERNEL ,"%08x%08x%08x%08x%08x" , -readl ((u32 *)uid+0 ), -readl ((u32 *)uid+1 ),readl ((u32 *)uid+2 ), -readl ((u32 *)uid+3 ),readl ((u32 *)uid+4 )); + uid[0 ], uid[1 ], uid[2 ], uid[3 ], uid[4 ]);iounmap (base);return retstr; }
Greg Kroah-Hartman
maintainerPATCH 486/658 arm64: dts: qcom: sdm850-lenovo-yoga-c630: correct I2C12 pins drive strength
In reply to Greg Kroah-HartmanFrom: Krzysztof Kozlowski <[email protected]>
commit fd49776d8f458bba5499384131eddc0b8bcaf50c upstream.
The pin configuration (done with generic pin controller helpers and as expressed by bindings) requires children nodes with either:
1. "pins" property and the actual configuration,
2. another set of nodes with above point.
The qup_i2c12_default pin configuration used second method - with a "pinmux" child.
--- arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts +4 -2
@@ -298,8 +298,10 @@ }; &qup_i2c12_default { - drive-strength = <2>; - bias-disable; + pinmux { + drive-strength = <2>; + bias-disable; + }; }; &qup_uart6_default {
Greg Kroah-Hartman
maintainerPATCH 487/658 selftests: Use optional USERCFLAGS and USERLDFLAGS
In reply to Greg Kroah-HartmanFrom: Mickaël Salaün <[email protected]>
commit de3ee3f63400a23954e7c1ad1cb8c20f29ab6fe3 upstream.
This change enables to extend CFLAGS and LDFLAGS from command line, e.g. to extend compiler checks: make USERCFLAGS=-Werror USERLDFLAGS=-static
USERCFLAGS and USERLDFLAGS are documented in Documentation/kbuild/makefiles.rst and Documentation/kbuild/kbuild.rst
This should be backported (down to 5.10) to improve previous kernel versions testing as well.
--- tools/testing/selftests/lib.mk | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/lib.mk +5 -0
@@ -130,6 +130,11 @@ endef clean: $(CLEAN) +# Enables to extend CFLAGS and LDFLAGS from command line, e.g. +# make USERCFLAGS=-Werror USERLDFLAGS=-static +CFLAGS += $(USERCFLAGS) +LDFLAGS += $(USERLDFLAGS) + # When make O= with kselftest target from main level # the following aren't defined. #
Greg Kroah-Hartman
maintainerPATCH 488/658 cpufreq: Init completion before kobject_init_and_add()
In reply to Greg Kroah-HartmanFrom: Yongqiang Liu <[email protected]>
commit 5c51054896bcce1d33d39fead2af73fec24f40b6 upstream.
In cpufreq_policy_alloc(), it will call uninitialed completion in cpufreq_sysfs_release() when kobject_init_and_add() fails. And that will cause a crash such as the following page fault in complete:
BUG: unable to handle page fault for address: fffffffffffffff8 [..] RIP: 0010:complete+0x98/0x1f0 [..] Call Trace: kobject_put+0x1be/0x4c0 cpufreq_online.cold+0xee/0x1fd cpufreq_add_dev+0x183/0x1e0 subsys_interface_register+0x3f5/0x4e0 cpufreq_register_driver+0x3b7/0x670 acpi_cpufreq_init+0x56c/0x1000 [acpi_cpufreq] do_one_initcall+0x13d/0x780 do_init_module+0x1c3/0x630 load_module+0x6e67/0x73b0 __do_sys_finit_module+0x181/0x240 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd
--- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +1 -1
@@ -1204,6 +1204,7 @@ static struct cpufreq_policy *cpufreq_poif (!zalloc_cpumask_var (&policy->real_cpus,GFP_KERNEL )) goto err_free_rcpumask; +init_completion (&policy->kobj_unregister); ret =kobject_init_and_add (&policy->kobj, &ktype_cpufreq, cpufreq_global_kobject,"policy%u" , cpu);if (ret) {
@@ -1242,7 +1243,6 @@ static struct cpufreq_policy *cpufreq_poinit_rwsem (&policy->rwsem);spin_lock_init (&policy->transition_lock);init_waitqueue_head (&policy->transition_wait); -init_completion (&policy->kobj_unregister);INIT_WORK (&policy->update, handle_update); policy->cpu = cpu;
Greg Kroah-Hartman
maintainerPATCH 489/658 binfmt: Move install_exec_creds after setup_new_exec to match binfmt_elf
In reply to Greg Kroah-HartmanFrom: Eric W. Biederman <[email protected]>
[ Upstream commit e7f7785449a1f459a4a3ca92f82f56fb054dd2b9 ]
In 2016 Linus moved install_exec_creds immediately after setup_new_exec, in binfmt_elf as a cleanup and as part of closing a potential information leak.
Perform the same cleanup for the other binary formats.
Different binary formats doing the same things the same way makes exec easier to reason about and easier to maintain.
Greg Ungerer reports:
Quoted 3 lines
I tested the the whole series on non-MMU m68k and non-MMU arm (exercising
binfmt_flat) and it all tested out with no problems, so for thebinfmt_flatchanges:
Ref: 9f834ec18def ("binfmt_elf: switch to new creds when switching to new mm")
Stable-dep-of: e7f703ff2507 ("binfmt: Fix error return code in load_elf_fdpic_binary()")
--- arch/x86/ia32/ia32_aout.c | 3 +-- fs/binfmt_aout.c | 2 +- fs/binfmt_elf_fdpic.c | 2 +- fs/binfmt_flat.c | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-)
arch/x86/ia32/ia32_aout.c +1 -2
@@ -140,6 +140,7 @@ static int load_aout_binary(struct linux_binprm *bprm)set_personality_ia32 (false);setup_new_exec (bprm); +install_exec_creds (bprm); regs->cs = __USER32_CS; regs->r8 = regs->r9 = regs->r10 = regs->r11 = regs->r12 =
@@ -156,8 +157,6 @@ static int load_aout_binary(struct linux_binprm *bprm)if (retval <0 )return retval; -install_exec_creds (bprm); -if (N_MAGIC (ex) ==OMAGIC ) {unsigned long text_addr, map_size;
fs/binfmt_aout.c +1 -1
@@ -162,6 +162,7 @@ static int load_aout_binary(struct linux_binprm * bprm)set_personality (PER_LINUX );#endif setup_new_exec (bprm); +install_exec_creds (bprm); current->mm->end_code = ex.a_text + (current->mm->start_code =N_TXTADDR (ex));
@@ -174,7 +175,6 @@ static int load_aout_binary(struct linux_binprm * bprm)if (retval <0 )return retval; -install_exec_creds (bprm);if (N_MAGIC (ex) ==OMAGIC ) {unsigned long text_addr, map_size;
fs/binfmt_elf_fdpic.c +1 -1
@@ -353,6 +353,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) current->personality |=READ_IMPLIES_EXEC ;setup_new_exec (bprm); +install_exec_creds (bprm);set_binfmt (&elf_fdpic_format);
@@ -434,7 +435,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) current->mm->start_stack = current->mm->start_brk + stack_size;#endif -install_exec_creds (bprm);if (create_elf_fdpic_tables (bprm, current->mm, &exec_params, &interp_params) <0 ) goto error;
fs/binfmt_flat.c +1 -2
@@ -565,6 +565,7 @@ static int load_flat_file(struct linux_binprm *bprm,/* OK, This is the point of no return */ set_personality (PER_LINUX_32BIT );setup_new_exec (bprm); +install_exec_creds (bprm); }/*
@@ -992,8 +993,6 @@ static int load_flat_binary(struct linux_binprm *bprm) } } -install_exec_creds (bprm); -set_binfmt (&flat_format);#ifdef CONFIG_MMU
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 490/658 binfmt: Fix error return code in load_elf_fdpic_binary()
In reply to Greg Kroah-HartmanFrom: Wang Yufen <[email protected]>
[ Upstream commit e7f703ff2507f4e9f496da96cd4b78fd3026120c ]
Fix to return a negative error code from create_elf_fdpic_tables() instead of 0.
--- fs/binfmt_elf_fdpic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/binfmt_elf_fdpic.c +3 -2
@@ -435,8 +435,9 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) current->mm->start_stack = current->mm->start_brk + stack_size;#endif -if (create_elf_fdpic_tables (bprm, current->mm, - &exec_params, &interp_params) <0 ) + retval =create_elf_fdpic_tables (bprm, current->mm, &exec_params, + &interp_params); +if (retval <0 ) goto error;kdebug ("- start_code %lx" , current->mm->start_code);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 491/658 dm cache: Fix ABBA deadlock between shrink_slab and dm_cache_metadata_abort
In reply to Greg Kroah-HartmanFrom: Mike Snitzer <[email protected]>
commit 352b837a5541690d4f843819028cf2b8be83d424 upstream.
Same ABBA deadlock pattern fixed in commit 4b60f452ec51 ("dm thin: Fix ABBA deadlock between shrink_slab and dm_pool_abort_metadata") to DM-cache's metadata.
--- drivers/md/dm-cache-metadata.c | 54 +++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-)
drivers/md/dm-cache-metadata.c +47 -7
@@ -551,11 +551,13 @@ static int __create_persistent_data_objereturn r; } -static void __destroy_persistent_data_objects (struct dm_cache_metadata *cmd) +static void __destroy_persistent_data_objects (struct dm_cache_metadata *cmd, +bool destroy_bm) {dm_sm_destroy (cmd->metadata_sm);dm_tm_destroy (cmd->tm); -dm_block_manager_destroy (cmd->bm); +if (destroy_bm) +dm_block_manager_destroy (cmd->bm); }typedef unsigned long (*flags_mutator )(unsigned long );
@@ -826,7 +828,7 @@ static struct dm_cache_metadata *lookup_ cmd2 =lookup (bdev);if (cmd2) {mutex_unlock (&table_lock); -__destroy_persistent_data_objects (cmd); +__destroy_persistent_data_objects (cmd, true);kfree (cmd);return cmd2; }
@@ -874,7 +876,7 @@ void dm_cache_metadata_close(struct dm_cmutex_unlock (&table_lock);if (!cmd->fail_io) -__destroy_persistent_data_objects (cmd); +__destroy_persistent_data_objects (cmd, true);kfree (cmd); } }
@@ -1808,14 +1810,52 @@ int dm_cache_metadata_needs_check(structint dm_cache_metadata_abort (struct dm_cache_metadata *cmd) { -int r; +int r = -EINVAL ; +struct dm_block_manager *old_bm =NULL , *new_bm =NULL ; + +/* fail_io is double-checked with cmd->root_lock held below */ +if (unlikely (cmd->fail_io)) +return r; + +/* +* Replacement block manager (new_bm) is created and old_bm destroyed outside of +* cmd root_lock to avoid ABBA deadlock that would result (due to life-cycle of +* shrinker associated with the block manager's bufio client vs cmd root_lock). +* - must take shrinker_rwsem without holding cmd->root_lock +*/ + new_bm =dm_block_manager_create (cmd->bdev,DM_CACHE_METADATA_BLOCK_SIZE <<SECTOR_SHIFT , +CACHE_MAX_CONCURRENT_LOCKS );WRITE_LOCK (cmd); -__destroy_persistent_data_objects (cmd); - r =__create_persistent_data_objects (cmd, false); +if (cmd->fail_io) { +WRITE_UNLOCK (cmd); + goto out; + } + +__destroy_persistent_data_objects (cmd, false); + old_bm = cmd->bm; +if (IS_ERR (new_bm)) { +DMERR ("could not create block manager during abort" ); + cmd->bm =NULL ; + r =PTR_ERR (new_bm); + goto out_unlock; + } + + cmd->bm = new_bm; + r =__open_or_format_metadata (cmd, false); +if (r) { + cmd->bm =NULL ; + goto out_unlock; + } + new_bm =NULL ; +out_unlock:if (r) cmd->fail_io = true;WRITE_UNLOCK (cmd); +dm_block_manager_destroy (old_bm); +out: +if (new_bm && !IS_ERR (new_bm)) +dm_block_manager_destroy (new_bm);return r; }
Greg Kroah-Hartman
maintainerPATCH 492/658 dm thin: Fix ABBA deadlock between shrink_slab and dm_pool_abort_metadata
In reply to Greg Kroah-HartmanFrom: Zhihao Cheng <[email protected]>
commit 8111964f1b8524c4bb56b02cd9c7a37725ea21fd upstream.
Following concurrent processes:
P1(drop cache) P2(kworker)drop_caches_sysctl_handler
drop_slab
shrink_slab
down_read(&shrinker_rwsem) - LOCK A
do_shrink_slab
super_cache_scan
prune_icache_sb
dispose_list
evict
ext4_evict_inode
ext4_clear_inode
ext4_discard_preallocations
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowait
ext4_read_bh_nowait
submit_bh
dm_submit_bio
do_worker
process_deferred_bios
commit
metadata_operation_failed
dm_pool_abort_metadata
down_write(&pmd->root_lock) - LOCK B
__destroy_persistent_data_objects
dm_block_manager_destroy
dm_bufio_client_destroy
unregister_shrinker
down_write(&shrinker_rwsem)
thin_map |
dm_thin_find_block ↓
down_read(&pmd->root_lock) --> ABBA deadlock, which triggers hung task:
[ 76.974820] INFO: task kworker/u4:3:63 blocked for more than 15 seconds. [ 76.976019] Not tainted 6.1.0-rc4-00011-g8f17dd350364-dirty #910 [ 76.978521] task:kworker/u4:3 state:D stack:0 pid:63 ppid:2 [ 76.978534] Workqueue: dm-thin do_worker [ 76.978552] Call Trace: [ 76.978564] __schedule+0x6ba/0x10f0 [ 76.978582] schedule+0x9d/0x1e0 [ 76.978588] rwsem_down_write_slowpath+0x587/0xdf0 [ 76.978600] down_write+0xec/0x110 [ 76.978607] unregister_shrinker+0x2c/0xf0 [ 76.978616] dm_bufio_client_destroy+0x116/0x3d0 [ 76.978625] dm_block_manager_destroy+0x19/0x40 [ 76.978629] __destroy_persistent_data_objects+0x5e/0x70 [ 76.978636] dm_pool_abort_metadata+0x8e/0x100 [ 76.978643] metadata_operation_failed+0x86/0x110 [ 76.978649] commit+0x6a/0x230 [ 76.978655] do_worker+0xc6e/0xd90 [ 76.978702] process_one_work+0x269/0x630 [ 76.978714] worker_thread+0x266/0x630 [ 76.978730] kthread+0x151/0x1b0 [ 76.978772] INFO: task test.sh:2646 blocked for more than 15 seconds. [ 76.979756] Not tainted 6.1.0-rc4-00011-g8f17dd350364-dirty #910 [ 76.982111] task:test.sh state:D stack:0 pid:2646 ppid:2459 [ 76.982128] Call Trace: [ 76.982139] __schedule+0x6ba/0x10f0 [ 76.982155] schedule+0x9d/0x1e0 [ 76.982159] rwsem_down_read_slowpath+0x4f4/0x910 [ 76.982173] down_read+0x84/0x170 [ 76.982177] dm_thin_find_block+0x4c/0xd0 [ 76.982183] thin_map+0x201/0x3d0 [ 76.982188] __map_bio+0x5b/0x350 [ 76.982195] dm_submit_bio+0x2b6/0x930 [ 76.982202] __submit_bio+0x123/0x2d0 [ 76.982209] submit_bio_noacct_nocheck+0x101/0x3e0 [ 76.982222] submit_bio_noacct+0x389/0x770 [ 76.982227] submit_bio+0x50/0xc0 [ 76.982232] submit_bh_wbc+0x15e/0x230 [ 76.982238] submit_bh+0x14/0x20 [ 76.982241] ext4_read_bh_nowait+0xc5/0x130 [ 76.982247] ext4_read_block_bitmap_nowait+0x340/0xc60 [ 76.982254] ext4_mb_init_cache+0x1ce/0xdc0 [ 76.982259] ext4_mb_load_buddy_gfp+0x987/0xfa0 [ 76.982263] ext4_discard_preallocations+0x45d/0x830 [ 76.982274] ext4_clear_inode+0x48/0xf0 [ 76.982280] ext4_evict_inode+0xcf/0xc70 [ 76.982285] evict+0x119/0x2b0 [ 76.982290] dispose_list+0x43/0xa0 [ 76.982294] prune_icache_sb+0x64/0x90 [ 76.982298] super_cache_scan+0x155/0x210 [ 76.982303] do_shrink_slab+0x19e/0x4e0 [ 76.982310] shrink_slab+0x2bd/0x450 [ 76.982317] drop_slab+0xcc/0x1a0 [ 76.982323] drop_caches_sysctl_handler+0xb7/0xe0 [ 76.982327] proc_sys_call_handler+0x1bc/0x300 [ 76.982331] proc_sys_write+0x17/0x20 [ 76.982334] vfs_write+0x3d3/0x570 [ 76.982342] ksys_write+0x73/0x160 [ 76.982347] __x64_sys_write+0x1e/0x30 [ 76.982352] do_syscall_64+0x35/0x80 [ 76.982357] entry_SYSCALL_64_after_hwframe+0x63/0xcd
Function metadata_operation_failed() is called when operations failed on dm pool metadata, dm pool will destroy and recreate metadata. So, shrinker will be unregistered and registered, which could down write shrinker_rwsem under pmd_write_lock.
Fix it by allocating dm_block_manager before locking pmd->root_lock and destroying old dm_block_manager after unlocking pmd->root_lock, then old dm_block_manager is replaced with new dm_block_manager under pmd->root_lock. So, shrinker register/unregister could be done without holding pmd->root_lock.
Fetch a reproducer in [Link].
--- drivers/md/dm-thin-metadata.c | 51 +++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-)
drivers/md/dm-thin-metadata.c +43 -8
@@ -753,13 +753,15 @@ static int __create_persistent_data_objereturn r; } -static void __destroy_persistent_data_objects (struct dm_pool_metadata *pmd) +static void __destroy_persistent_data_objects (struct dm_pool_metadata *pmd, +bool destroy_bm) {dm_sm_destroy (pmd->data_sm);dm_sm_destroy (pmd->metadata_sm);dm_tm_destroy (pmd->nb_tm);dm_tm_destroy (pmd->tm); -dm_block_manager_destroy (pmd->bm); +if (destroy_bm) +dm_block_manager_destroy (pmd->bm); }static int __begin_transaction (struct dm_pool_metadata *pmd)
@@ -966,7 +968,7 @@ int dm_pool_metadata_close(struct dm_poo }pmd_write_unlock (pmd);if (!pmd->fail_io) -__destroy_persistent_data_objects (pmd); +__destroy_persistent_data_objects (pmd, true);kfree (pmd);return 0 ;
@@ -1875,19 +1877,52 @@ static void __set_abort_with_changes_flaint dm_pool_abort_metadata (struct dm_pool_metadata *pmd) {int r = -EINVAL ; +struct dm_block_manager *old_bm =NULL , *new_bm =NULL ; + +/* fail_io is double-checked with pmd->root_lock held below */ +if (unlikely (pmd->fail_io)) +return r; + +/* +* Replacement block manager (new_bm) is created and old_bm destroyed outside of +* pmd root_lock to avoid ABBA deadlock that would result (due to life-cycle of +* shrinker associated with the block manager's bufio client vs pmd root_lock). +* - must take shrinker_rwsem without holding pmd->root_lock +*/ + new_bm =dm_block_manager_create (pmd->bdev,THIN_METADATA_BLOCK_SIZE <<SECTOR_SHIFT , +THIN_MAX_CONCURRENT_LOCKS );pmd_write_lock (pmd); -if (pmd->fail_io) +if (pmd->fail_io) { +pmd_write_unlock (pmd); goto out; + }__set_abort_with_changes_flags (pmd); -__destroy_persistent_data_objects (pmd); - r =__create_persistent_data_objects (pmd, false); +__destroy_persistent_data_objects (pmd, false); + old_bm = pmd->bm; +if (IS_ERR (new_bm)) { +DMERR ("could not create block manager during abort" ); + pmd->bm =NULL ; + r =PTR_ERR (new_bm); + goto out_unlock; + } + + pmd->bm = new_bm; + r =__open_or_format_metadata (pmd, false); +if (r) { + pmd->bm =NULL ; + goto out_unlock; + } + new_bm =NULL ; +out_unlock:if (r) pmd->fail_io = true; - -out:pmd_write_unlock (pmd); +dm_block_manager_destroy (old_bm); +out: +if (new_bm && !IS_ERR (new_bm)) +dm_block_manager_destroy (new_bm);return r; }
Greg Kroah-Hartman
maintainerPATCH 493/658 dm thin: Use last transactions pmd->root when commit failed
In reply to Greg Kroah-HartmanFrom: Zhihao Cheng <[email protected]>
commit 7991dbff6849f67e823b7cc0c15e5a90b0549b9f upstream.
Recently we found a softlock up problem in dm thin pool btree lookup code due to corrupted metadata:
Kernel panic - not syncing: softlockup: hung tasks CPU: 7 PID: 2669225 Comm: kworker/u16:3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) Workqueue: dm-thin do_worker [dm_thin_pool] Call Trace: <IRQ> dump_stack+0x9c/0xd3 panic+0x35d/0x6b9 watchdog_timer_fn.cold+0x16/0x25 __run_hrtimer+0xa2/0x2d0 </IRQ> RIP: 0010:__relink_lru+0x102/0x220 [dm_bufio] __bufio_new+0x11f/0x4f0 [dm_bufio] new_read+0xa3/0x1e0 [dm_bufio] dm_bm_read_lock+0x33/0xd0 [dm_persistent_data] ro_step+0x63/0x100 [dm_persistent_data] btree_lookup_raw.constprop.0+0x44/0x220 [dm_persistent_data] dm_btree_lookup+0x16f/0x210 [dm_persistent_data] dm_thin_find_block+0x12c/0x210 [dm_thin_pool] __process_bio_read_only+0xc5/0x400 [dm_thin_pool] process_thin_deferred_bios+0x1a4/0x4a0 [dm_thin_pool] process_one_work+0x3c5/0x730
Following process may generate a broken btree mixed with fresh and stale btree nodes, which could get dm thin trapped in an infinite loop while looking up data block:
Transaction 1: pmd->root = A, A->B->C // One path in btree
pmd->root = X, X->Y->Z // Copy-up
Transaction 2: X,Z is updated on disk, Y write failed.
// Commit failed, dm thin becomes read-only.
process_bio_read_only
dm_thin_find_block
__find_block
dm_btree_lookup(pmd->root)The pmd->root points to a broken btree, Y may contain stale node pointing to any block, for example X, which gets dm thin trapped into a dead loop while looking up Z.
Fix this by setting pmd->root in __open_metadata(), so that dm thin will use the last transaction's pmd->root if commit failed.
Fetch a reproducer in [Link].
Linke: https://bugzilla.kernel.org/show_bug.cgi?id=216790
--- drivers/md/dm-thin-metadata.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/md/dm-thin-metadata.c +9 -0
@@ -701,6 +701,15 @@ static int __open_metadata(struct dm_poo goto bad_cleanup_data_sm; } +/* +* For pool metadata opening process, root setting is redundant +* because it will be set again in __begin_transaction(). But dm +* pool aborting process really needs to get last transaction's +* root to avoid accessing broken btree. +*/ + pmd->root =le64_to_cpu (disk_super->data_mapping_root); + pmd->details_root =le64_to_cpu (disk_super->device_details_root); +__setup_btree_details (pmd);dm_bm_unlock (sblock);
Greg Kroah-Hartman
maintainerPATCH 494/658 dm thin: Fix UAF in run_timer_softirq()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit 88430ebcbc0ec637b710b947738839848c20feff upstream.
When dm_resume() and dm_destroy() are concurrent, it will lead to UAF, as follows:
BUG: KASAN: use-after-free in __run_timers+0x173/0x710 Write of size 8 at addr ffff88816d9490f0 by task swapper/0/0 <snip> Call Trace: <IRQ> dump_stack_lvl+0x73/0x9f print_report.cold+0x132/0xaa2 _raw_spin_lock_irqsave+0xcd/0x160 __run_timers+0x173/0x710 kasan_report+0xad/0x110 __run_timers+0x173/0x710 __asan_store8+0x9c/0x140 __run_timers+0x173/0x710 call_timer_fn+0x310/0x310 pvclock_clocksource_read+0xfa/0x250 kvm_clock_read+0x2c/0x70 kvm_clock_get_cycles+0xd/0x20 ktime_get+0x5c/0x110 lapic_next_event+0x38/0x50 clockevents_program_event+0xf1/0x1e0 run_timer_softirq+0x49/0x90 __do_softirq+0x16e/0x62c __irq_exit_rcu+0x1fa/0x270 irq_exit_rcu+0x12/0x20 sysvec_apic_timer_interrupt+0x8e/0xc0
One of the concurrency UAF can be shown as below:
use free
do_resume |
__find_device_hash_cell |
dm_get |
atomic_inc(&md->holders) |
| dm_destroy
| __dm_destroy
| if (!dm_suspended_md(md))
| atomic_read(&md->holders)
| msleep(1)
dm_resume |
__dm_resume |
dm_table_resume_targets |
pool_resume |
do_waker #add delay work |
dm_put |
atomic_dec(&md->holders) |
| dm_table_destroy
| pool_dtr
| __pool_dec
| __pool_destroy
| destroy_workqueue
| kfree(pool) # free pool time out__do_softirq
run_timer_softirq # pool has already been freed
This can be easily reproduced using:
1. create thin-pool
2. dmsetup suspend pool
3. dmsetup resume pool
4. dmsetup remove_all # Concurrent with 3
The root cause of this UAF bug is that dm_resume() adds timer after dm_destroy() skips cancelling the timer because of suspend status. After timeout, it will call run_timer_softirq(), however pool has already been freed. The concurrency UAF bug will happen.
Therefore, cancelling timer again in __pool_destroy().
--- drivers/md/dm-thin.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm-thin.c +2 -0
@@ -2931,6 +2931,8 @@ static void __pool_destroy(struct pool *dm_bio_prison_destroy (pool->prison);dm_kcopyd_client_destroy (pool->copier); +cancel_delayed_work_sync (&pool->waker); +cancel_delayed_work_sync (&pool->no_space_timeout);if (pool->wq)destroy_workqueue (pool->wq);
Greg Kroah-Hartman
maintainerPATCH 495/658 dm integrity: Fix UAF in dm_integrity_dtr()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit f50cb2cbabd6c4a60add93d72451728f86e4791c upstream.
Dm_integrity also has the same UAF problem when dm_resume() and dm_destroy() are concurrent.
Therefore, cancelling timer again in dm_integrity_dtr().
--- drivers/md/dm-integrity.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm-integrity.c +2 -0
@@ -4195,6 +4195,8 @@ static void dm_integrity_dtr(struct dm_tBUG_ON (!RB_EMPTY_ROOT (&ic->in_progress));BUG_ON (!list_empty (&ic->wait_list)); +if (ic->mode =='B' ) +cancel_delayed_work_sync (&ic->bitmap_flush_work);if (ic->metadata_wq)destroy_workqueue (ic->metadata_wq);if (ic->wait_wq)
Greg Kroah-Hartman
maintainerPATCH 496/658 dm clone: Fix UAF in clone_dtr()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit e4b5957c6f749a501c464f92792f1c8e26b61a94 upstream.
Dm_clone also has the same UAF problem when dm_resume() and dm_destroy() are concurrent.
Therefore, cancelling timer again in clone_dtr().
--- drivers/md/dm-clone-target.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/dm-clone-target.c +1 -0
@@ -1977,6 +1977,7 @@ static void clone_dtr(struct dm_target *mempool_exit (&clone->hydration_pool);dm_kcopyd_client_destroy (clone->kcopyd_client); +cancel_delayed_work_sync (&clone->waker);destroy_workqueue (clone->wq);hash_table_exit (clone);dm_clone_metadata_close (clone->cmd);
Greg Kroah-Hartman
maintainerPATCH 497/658 dm cache: Fix UAF in destroy()
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
commit 6a459d8edbdbe7b24db42a5a9f21e6aa9e00c2aa upstream.
Dm_cache also has the same UAF problem when dm_resume() and dm_destroy() are concurrent.
Therefore, cancelling timer again in destroy().
--- drivers/md/dm-cache-target.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/dm-cache-target.c +1 -0
@@ -1992,6 +1992,7 @@ static void destroy(struct cache *cache)if (cache->prison)dm_bio_prison_destroy_v2 (cache->prison); +cancel_delayed_work_sync (&cache->waker);if (cache->wq)destroy_workqueue (cache->wq);
Greg Kroah-Hartman
maintainerPATCH 498/658 dm cache: set needs_check flag after aborting metadata
In reply to Greg Kroah-HartmanFrom: Mike Snitzer <[email protected]>
commit 6b9973861cb2e96dcd0bb0f1baddc5c034207c5c upstream.
Otherwise the commit that will be aborted will be associated with the metadata objects that will be torn down. Must write needs_check flag to metadata with a reset block manager.
Found through code-inspection (and compared against dm-thin.c).
--- drivers/md/dm-cache-target.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/dm-cache-target.c +5 -5
@@ -1011,16 +1011,16 @@ static void abort_transaction(struct cacif (get_cache_mode (cache) >=CM_READ_ONLY )return ; -if (dm_cache_metadata_set_needs_check (cache->cmd)) { -DMERR ("%s: failed to set 'needs_check' flag in metadata" , dev_name); -set_cache_mode (cache,CM_FAIL ); - } -DMERR_LIMIT ("%s: aborting current metadata transaction" , dev_name);if (dm_cache_metadata_abort (cache->cmd)) {DMERR ("%s: failed to abort metadata transaction" , dev_name);set_cache_mode (cache,CM_FAIL ); } + +if (dm_cache_metadata_set_needs_check (cache->cmd)) { +DMERR ("%s: failed to set 'needs_check' flag in metadata" , dev_name); +set_cache_mode (cache,CM_FAIL ); + } }static void metadata_operation_failed (struct cache *cache,const char *op,int r)
Greg Kroah-Hartman
maintainerPATCH 499/658 tracing/hist: Fix out-of-bound write on action_data.var_ref_idx
In reply to Greg Kroah-HartmanFrom: Zheng Yejian <[email protected]>
commit 82470f7d9044842618c847a7166de2b7458157a7 upstream.
When generate a synthetic event with many params and then create a trace action for it [1], kernel panic happened [2].
It is because that in trace_action_create() 'data->n_params' is up to SYNTH_FIELDS_MAX (current value is 64), and array 'data->var_ref_idx' keeps indices into array 'hist_data->var_refs' for each synthetic event param, but the length of 'data->var_ref_idx' is TRACING_MAP_VARS_MAX (current value is 16), so out-of-bound write happened when 'data->n_params' more than 16. In this case, 'data->match_data.event' is overwritten and eventually cause the panic.
To solve the issue, adjust the length of 'data->var_ref_idx' to be SYNTH_FIELDS_MAX and add sanity checks to avoid out-of-bound write.
[1]
# cd /sys/kernel/tracing/ # echo "my_synth_event int v1; int v2; int v3; int v4; int v5; int v6;\ int v7; int v8; int v9; int v10; int v11; int v12; int v13; int v14;\ int v15; int v16; int v17; int v18; int v19; int v20; int v21; int v22;\ int v23; int v24; int v25; int v26; int v27; int v28; int v29; int v30;\ int v31; int v32; int v33; int v34; int v35; int v36; int v37; int v38;\ int v39; int v40; int v41; int v42; int v43; int v44; int v45; int v46;\ int v47; int v48; int v49; int v50; int v51; int v52; int v53; int v54;\ int v55; int v56; int v57; int v58; int v59; int v60; int v61; int v62;\ int v63" >> synthetic_events # echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="bash"' >> \ events/sched/sched_waking/trigger # echo "hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(\ pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,\ pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,\ pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,pid,\ pid,pid,pid,pid,pid,pid,pid,pid,pid)" >> events/sched/sched_switch/trigger
[2]
BUG: unable to handle page fault for address: ffff91c900000000 PGD 61001067 P4D 61001067 PUD 0 Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 2 PID: 322 Comm: bash Tainted: G W 6.1.0-rc8+ #229 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 RIP: 0010:strcmp+0xc/0x30 Code: 75 f7 31 d2 44 0f b6 04 16 44 88 04 11 48 83 c2 01 45 84 c0 75 ee c3 cc cc cc cc 0f 1f 00 31 c0 eb 08 48 83 c0 01 84 d2 74 13 <0f> b6 14 07 3a 14 06 74 ef 19 c0 83 c8 01 c3 cc cc cc cc 31 c3 RSP: 0018:ffff9b3b00f53c48 EFLAGS: 00000246 RAX: 0000000000000000 RBX: ffffffffba958a68 RCX: 0000000000000000 RDX: 0000000000000010 RSI: ffff91c943d33a90 RDI: ffff91c900000000 RBP: ffff91c900000000 R08: 00000018d604b529 R09: 0000000000000000 R10: ffff91c9483eddb1 R11: ffff91ca483eddab R12: ffff91c946171580 R13: ffff91c9479f0538 R14: ffff91c9457c2848 R15: ffff91c9479f0538 FS: 00007f1d1cfbe740(0000) GS:ffff91c9bdc80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff91c900000000 CR3: 0000000006316000 CR4: 00000000000006e0 Call Trace: <TASK> __find_event_file+0x55/0x90 action_create+0x76c/0x1060 event_hist_trigger_parse+0x146d/0x2060 ? event_trigger_write+0x31/0xd0 trigger_process_regex+0xbb/0x110 event_trigger_write+0x6b/0xd0 vfs_write+0xc8/0x3e0 ? alloc_fd+0xc0/0x160 ? preempt_count_add+0x4d/0xa0 ? preempt_count_add+0x70/0xa0 ksys_write+0x5f/0xe0 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7f1d1d0cf077 Code: 64 89 02 48 c7 c0 ff ff ff ff eb bb 0f 1f 80 00 00 00 00 f3 0f 1e
fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 51 c3 48 83 ec 28 48 89 54 24 18 48 89 74
RSP: 002b:00007ffcebb0e568 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000000143 RCX: 00007f1d1d0cf077
RDX: 0000000000000143 RSI: 00005639265aa7e0 RDI: 0000000000000001
RBP: 00005639265aa7e0 R08: 000000000000000a R09: 0000000000000142
R10: 000056392639c017 R11: 0000000000000246 R12: 0000000000000143
R13: 00007f1d1d1ae6a0 R14: 00007f1d1d1aa4a0 R15: 00007f1d1d1a98a0
</TASK> Modules linked in: CR2: ffff91c900000000 ---[ end trace 0000000000000000 ]--- RIP: 0010:strcmp+0xc/0x30 Code: 75 f7 31 d2 44 0f b6 04 16 44 88 04 11 48 83 c2 01 45 84 c0 75 ee c3 cc cc cc cc 0f 1f 00 31 c0 eb 08 48 83 c0 01 84 d2 74 13 <0f> b6 14 07 3a 14 06 74 ef 19 c0 83 c8 01 c3 cc cc cc cc 31 c3 RSP: 0018:ffff9b3b00f53c48 EFLAGS: 00000246 RAX: 0000000000000000 RBX: ffffffffba958a68 RCX: 0000000000000000 RDX: 0000000000000010 RSI: ffff91c943d33a90 RDI: ffff91c900000000 RBP: ffff91c900000000 R08: 00000018d604b529 R09: 0000000000000000 R10: ffff91c9483eddb1 R11: ffff91ca483eddab R12: ffff91c946171580 R13: ffff91c9479f0538 R14: ffff91c9457c2848 R15: ffff91c9479f0538 FS: 00007f1d1cfbe740(0000) GS:ffff91c9bdc80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff91c900000000 CR3: 0000000006316000 CR4: 00000000000006e0
--- kernel/trace/trace_events_hist.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +8 -2
@@ -479,7 +479,7 @@ struct action_data {* event param, and is passed to the synthetic event * invocation. */ -unsigned int var_ref_idx[TRACING_MAP_VARS_MAX ]; +unsigned int var_ref_idx[SYNTH_FIELDS_MAX ];struct synth_event *synth_event;bool use_trace_keyword;char *synth_event_name;
@@ -2752,7 +2752,9 @@ static struct hist_field *create_var_refreturn ref_field; } } - +/* Sanity check to avoid out-of-bound write on 'hist_data->var_refs' */ +if (hist_data->n_var_refs >=TRACING_MAP_VARS_MAX ) +return NULL ; ref_field =create_hist_field (var_field->hist_data,NULL , flags,NULL );if (ref_field) {if (init_var_ref (ref_field, var_field, system, event_name)) {
@@ -4338,6 +4340,10 @@ static int trace_action_create(struct hilockdep_assert_held (&event_mutex); +/* Sanity check to avoid out-of-bound write on 'data->var_ref_idx' */ +if (data->n_params >SYNTH_FIELDS_MAX ) +return -EINVAL ; +if (data->use_trace_keyword) synth_event_name = data->synth_event_name;else
Greg Kroah-Hartman
maintainerPATCH 500/658 x86/microcode/intel: Do not retry microcode reloading on the APs
In reply to Greg Kroah-HartmanFrom: Ashok Raj <[email protected]>
commit be1b670f61443aa5d0d01782e9b8ea0ee825d018 upstream.
The retries in load_ucode_intel_ap() were in place to support systems with mixed steppings. Mixed steppings are no longer supported and there is only one microcode image at a time. Any retries will simply reattempt to apply the same image over and over without making progress.
[ bp: Zap the circumstantial reasoning from the commit message. ]
--- arch/x86/kernel/cpu/microcode/intel.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +1 -7
@@ -659,7 +659,6 @@ void load_ucode_intel_ap(void)else iup = &intel_ucode_patch; -reget:if (!*iup) { patch =__load_ucode_intel (&uci);if (!patch)
@@ -670,12 +669,7 @@ reget: uci.mc = *iup; -if (apply_microcode_early (&uci, true)) { -/* Mixed-silicon system? Try to refetch the proper patch: */ - *iup =NULL ; - - goto reget; - } +apply_microcode_early (&uci, true); }static struct microcode_intel *find_patch (struct ucode_cpu_info *uci)
Greg Kroah-Hartman
maintainerPATCH 501/658 tracing/hist: Fix wrong return value in parse_action_params()
In reply to Greg Kroah-HartmanFrom: Zheng Yejian <[email protected]>
commit 2cc6a528882d0e0ccbc1bca5f95b8c963cedac54 upstream.
When number of synth fields is more than SYNTH_FIELDS_MAX, parse_action_params() should return -EINVAL.
--- kernel/trace/trace_events_hist.c | 1 + 1 file changed, 1 insertion(+)
kernel/trace/trace_events_hist.c +1 -0
@@ -4016,6 +4016,7 @@ static int parse_action_params(struct trwhile (params) {if (data->n_params >=SYNTH_FIELDS_MAX ) {hist_err (tr,HIST_ERR_TOO_MANY_PARAMS ,0 ); + ret = -EINVAL ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 502/658 tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line
In reply to Greg Kroah-HartmanFrom: Yang Jihong <[email protected]>
commit c1ac03af6ed45d05786c219d102f37eb44880f28 upstream.
print_trace_line may overflow seq_file buffer. If the event is not consumed, the while loop keeps peeking this event, causing a infinite loop.
--- kernel/trace/trace.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
kernel/trace/trace.c +14 -1
@@ -6101,7 +6101,20 @@ waitagain: ret =print_trace_line (iter);if (ret ==TRACE_TYPE_PARTIAL_LINE ) { -/* don't print partial lines */ +/* +* If one print_trace_line() fills entire trace_seq in one shot, +* trace_seq_to_user() will returns -EBUSY because save_len == 0, +* In this case, we need to consume it, otherwise, loop will peek +* this event next time, resulting in an infinite loop. +*/ +if (save_len ==0 ) { + iter->seq.full =0 ; +trace_seq_puts (&iter->seq,"[LINE TOO BIG]\n" ); +trace_consume (iter); +break ; + } + +/* In other cases, don't print partial lines */ iter->seq.seq.len = save_len;break ; }
Greg Kroah-Hartman
maintainerPATCH 503/658 ARM: 9256/1: NWFPE: avoid compiler-generated __aeabi_uldivmod
In reply to Greg Kroah-HartmanFrom: Nick Desaulniers <[email protected]>
commit 3220022038b9a3845eea762af85f1c5694b9f861 upstream.
clang-15's ability to elide loops completely became more aggressive when it can deduce how a variable is being updated in a loop. Counting down one variable by an increment of another can be replaced by a modulo operation.
For 64b variables on 32b ARM EABI targets, this can result in the compiler generating calls to __aeabi_uldivmod, which it does for a do while loop in float64_rem().
For the kernel, we'd generally prefer that developers not open code 64b division via binary / operators and instead use the more explicit helpers from div64.h. On arm-linux-gnuabi targets, failure to do so can result in linkage failures due to undefined references to __aeabi_uldivmod().
While developers can avoid open coding divisions on 64b variables, the compiler doesn't know that the Linux kernel has a partial implementation of a compiler runtime (--rtlib) to enforce this convention.
It's also undecidable for the compiler whether the code in question would be faster to execute the loop vs elide it and do the 64b division.
While I actively avoid using the internal -mllvm command line flags, I think we get better code than using barrier() here, which will force reloads+spills in the loop for all toolchains.
--- arch/arm/nwfpe/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/nwfpe/Makefile +6 -0
@@ -11,3 +11,9 @@ nwfpe-y += fpa11.o fpa11_cpdo.o fpa11 entry.o nwfpe-$(CONFIG_FPE_NWFPE_XP) += extended_cpdo.o + +# Try really hard to avoid generating calls to __aeabi_uldivmod() from +# float64_rem() due to loop elision. +ifdef CONFIG_CC_IS_CLANG +CFLAGS_softfloat.o += -mllvm -replexitval=never +endif
Greg Kroah-Hartman
maintainerPATCH 504/658 media: dvb-core: Fix double free in dvb_register_device()
In reply to Greg Kroah-HartmanFrom: Keita Suzuki <[email protected]>
commit 6b0d0477fce747d4137aa65856318b55fba72198 upstream.
In function dvb_register_device() -> dvb_register_media_device() -> dvb_create_media_entity(), dvb->entity is allocated and initialized. If the initialization fails, it frees the dvb->entity, and return an error code. The caller takes the error code and handles the error by calling dvb_media_device_free(), which unregisters the entity and frees the field again if it is not NULL. As dvb->entity may not NULLed in dvb_create_media_entity() when the allocation of dvbdev->pad fails, a double free may occur. This may also cause an Use After free in media_device_unregister_entity().
Fix this by storing NULL to dvb->entity when it is freed.
--- drivers/media/dvb-core/dvbdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/dvb-core/dvbdev.c +1 -0
@@ -345,6 +345,7 @@ static int dvb_create_media_entity(struc GFP_KERNEL);if (!dvbdev->pads) {kfree (dvbdev->entity); + dvbdev->entity =NULL ;return -ENOMEM ; } }
Greg Kroah-Hartman
maintainerPATCH 505/658 media: dvb-core: Fix UAF due to refcount races at releasing
In reply to Greg Kroah-HartmanFrom: Takashi Iwai <[email protected]>
commit fd3d91ab1c6ab0628fe642dd570b56302c30a792 upstream.
The dvb-core tries to sync the releases of opened files at dvb_dmxdev_release() with two refcounts: dvbdev->users and dvr_dvbdev->users. A problem is present in those two syncs: when yet another dvb_demux_open() is called during those sync waits, dvb_demux_open() continues to process even if the device is being closed. This includes the increment of the former refcount, resulting in the leftover refcount after the sync of the latter refcount at dvb_dmxdev_release(). It ends up with use-after-free, since the function believes that all usages were gone and releases the resources.
This patch addresses the problem by adding the check of dmxdev->exit flag at dvb_demux_open(), just like dvb_dvr_open() already does. With the exit flag check, the second call of dvb_demux_open() fails, hence the further corruption can be avoided.
Also for avoiding the races of the dmxdev->exit flag reference, this patch serializes the dmxdev->exit set up and the sync waits with the dmxdev->mutex lock at dvb_dmxdev_release(). Without the mutex lock, dvb_demux_open() (or dvb_dvr_open()) may run concurrently with dvb_dmxdev_release(), which allows to skip the exit flag check and continue the open process that is being closed.
CVE-2022-41218 is assigned to those bugs above.
--- drivers/media/dvb-core/dmxdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/dvb-core/dmxdev.c +8 -0
@@ -800,6 +800,11 @@ static int dvb_demux_open(struct inode *if (mutex_lock_interruptible (&dmxdev->mutex))return -ERESTARTSYS ; +if (dmxdev->exit) { +mutex_unlock (&dmxdev->mutex); +return -ENODEV ; + } +for (i =0 ; i < dmxdev->filternum; i++)if (dmxdev->filter[i].state ==DMXDEV_STATE_FREE )break ;
@@ -1458,7 +1463,10 @@ EXPORT_SYMBOL(dvb_dmxdev_init);void dvb_dmxdev_release (struct dmxdev *dmxdev) { +mutex_lock (&dmxdev->mutex); dmxdev->exit =1 ; +mutex_unlock (&dmxdev->mutex); +if (dmxdev->dvbdev->users >1 ) {wait_event (dmxdev->dvbdev->wait_queue, dmxdev->dvbdev->users ==1 );
Greg Kroah-Hartman
maintainerPATCH 506/658 cifs: fix confusing debug message
In reply to Greg Kroah-HartmanFrom: Paulo Alcantara <[email protected]>
commit a85ceafd41927e41a4103d228a993df7edd8823b upstream.
Since rc was initialised to -ENOMEM in cifs_get_smb_ses(), when an existing smb session was found, free_xid() would be called and then print
CIFS: fs/cifs/connect.c: Existing tcp session with server found
CIFS: fs/cifs/connect.c: VFS: in cifs_get_smb_ses as Xid: 44 with uid: 0
CIFS: fs/cifs/connect.c: Existing smb sess found (status=1)
CIFS: fs/cifs/connect.c: VFS: leaving cifs_get_smb_ses (xid = 44) rc = -12
Fix this by initialising rc to 0 and then let free_xid() print this instead
CIFS: fs/cifs/connect.c: Existing tcp session with server found
CIFS: fs/cifs/connect.c: VFS: in cifs_get_smb_ses as Xid: 14 with uid: 0
CIFS: fs/cifs/connect.c: Existing smb sess found (status=1)
CIFS: fs/cifs/connect.c: VFS: leaving cifs_get_smb_ses (xid = 14) rc = 0
--- fs/cifs/connect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/cifs/connect.c +3 -1
@@ -3235,7 +3235,7 @@ cifs_set_cifscreds(struct smb_vol *vol _struct cifs_ses *cifs_get_smb_ses (struct TCP_Server_Info *server,struct smb_vol *volume_info) { -int rc = -ENOMEM ; +int rc =0 ;unsigned int xid;struct cifs_ses *ses;struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
@@ -3277,6 +3277,8 @@ cifs_get_smb_ses(struct TCP_Server_Inforeturn ses; } + rc = -ENOMEM ; +cifs_dbg (FYI ,"Existing smb sess not found\n" ); ses =sesInfoAlloc ();if (ses ==NULL )
Greg Kroah-Hartman
maintainerPATCH 507/658 cifs: fix missing display of three mount options
In reply to Greg Kroah-HartmanFrom: Steve French <[email protected]>
commit 2bfd81043e944af0e52835ef6d9b41795af22341 upstream.
Three mount options: "tcpnodelay" and "noautotune" and "noblocksend" were not displayed when passed in on cifs/smb3 mounts (e.g. displayed in /proc/mounts e.g.). No change to defaults so these are not displayed if not specified on mount.
--- fs/cifs/cifsfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/cifs/cifsfs.c +7 -1
@@ -609,9 +609,15 @@ cifs_show_options(struct seq_file *s, stseq_printf (s,",echo_interval=%lu" , tcon->ses->server->echo_interval /HZ ); -/* Only display max_credits if it was overridden on mount */ +/* Only display the following if overridden on mount */ if (tcon->ses->server->max_credits !=SMB2_MAX_CREDITS_AVAILABLE )seq_printf (s,",max_credits=%u" , tcon->ses->server->max_credits); +if (tcon->ses->server->tcp_nodelay) +seq_puts (s,",tcpnodelay" ); +if (tcon->ses->server->noautotune) +seq_puts (s,",noautotune" ); +if (tcon->ses->server->noblocksnd) +seq_puts (s,",noblocksend" );if (tcon->snapshot_time)seq_printf (s,",snapshot=%llu" , tcon->snapshot_time);
Greg Kroah-Hartman
maintainerPATCH 508/658 md/bitmap: Fix bitmap chunk size overflow issues
In reply to Greg Kroah-HartmanFrom: Florian-Ewald Mueller <[email protected]>
commit 4555211190798b6b6fa2c37667d175bf67945c78 upstream.
- limit bitmap chunk size internal u64 variable to values not overflowing the u32 bitmap superblock structure variable stored on persistent media
- assign bitmap chunk size internal u64 variable from unsigned values to avoid possible sign extension artifacts when assigning from a s32 value
The bug has been there since at least kernel 4.0.
Steps to reproduce it:
1: mdadm -C /dev/mdx -l 1 --bitmap=internal --bitmap-chunk=256M -e 1.2 -n2 /dev/rnbd1 /dev/rnbd2
2 resize member device rnbd1 and rnbd2 to 8 TB
3 mdadm --grow /dev/mdx --size=max
The bitmap_chunksize will overflow without patch.
--- drivers/md/md-bitmap.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/md/md-bitmap.c +12 -8
@@ -489,7 +489,7 @@ void md_bitmap_print_sb(struct bitmap *b sb =kmap_atomic (bitmap->storage.sb_page);pr_debug ("%s: bitmap file superblock:\n" ,bmname (bitmap));pr_debug (" magic: %08x\n" ,le32_to_cpu (sb->magic)); -pr_debug (" version: %d\n" ,le32_to_cpu (sb->version)); +pr_debug (" version: %u\n" ,le32_to_cpu (sb->version)); pr_debug(" uuid: %08x.%08x.%08x.%08x\n", le32_to_cpu(*(__le32 *)(sb->uuid+0)), le32_to_cpu(*(__le32 *)(sb->uuid+4)),
@@ -500,11 +500,11 @@ void md_bitmap_print_sb(struct bitmap *bpr_debug ("events cleared: %llu\n" , (unsigned long long )le64_to_cpu (sb->events_cleared));pr_debug (" state: %08x\n" ,le32_to_cpu (sb->state)); -pr_debug (" chunksize: %d B\n" ,le32_to_cpu (sb->chunksize)); -pr_debug (" daemon sleep: %ds\n" ,le32_to_cpu (sb->daemon_sleep)); +pr_debug (" chunksize: %u B\n" ,le32_to_cpu (sb->chunksize)); +pr_debug (" daemon sleep: %us\n" ,le32_to_cpu (sb->daemon_sleep));pr_debug (" sync size: %llu KB\n" , (unsigned long long )le64_to_cpu (sb->sync_size)/2 ); -pr_debug ("max write behind: %d\n" ,le32_to_cpu (sb->write_behind)); +pr_debug ("max write behind: %u\n" ,le32_to_cpu (sb->write_behind));kunmap_atomic (sb); }
@@ -2110,7 +2110,8 @@ int md_bitmap_resize(struct bitmap *bitm bytes =DIV_ROUND_UP (chunks,8 );if (!bitmap->mddev->bitmap_info.external) bytes +=sizeof (bitmap_super_t); - }while (bytes > (space <<9 )); + }while (bytes > (space <<9 ) && (chunkshift +BITMAP_BLOCK_SHIFT ) < + (BITS_PER_BYTE *sizeof (((bitmap_super_t *)0 )->chunksize) -1 )); }else chunkshift =ffz (~chunksize) -BITMAP_BLOCK_SHIFT ;
@@ -2155,7 +2156,7 @@ int md_bitmap_resize(struct bitmap *bitm bitmap->counts.missing_pages = pages; bitmap->counts.chunkshift = chunkshift; bitmap->counts.chunks = chunks; - bitmap->mddev->bitmap_info.chunksize =1 << (chunkshift + + bitmap->mddev->bitmap_info.chunksize =1UL << (chunkshift +BITMAP_BLOCK_SHIFT ); blocks = min(old_counts.chunks << old_counts.chunkshift,
@@ -2181,8 +2182,8 @@ int md_bitmap_resize(struct bitmap *bitm bitmap->counts.missing_pages = old_counts.pages; bitmap->counts.chunkshift = old_counts.chunkshift; bitmap->counts.chunks = old_counts.chunks; - bitmap->mddev->bitmap_info.chunksize =1 << (old_counts.chunkshift + -BITMAP_BLOCK_SHIFT ); + bitmap->mddev->bitmap_info.chunksize = +1UL << (old_counts.chunkshift +BITMAP_BLOCK_SHIFT ); blocks = old_counts.chunks << old_counts.chunkshift;pr_warn ("Could not pre-allocate in-memory bitmap for cluster raid\n" );break ;
@@ -2523,6 +2524,9 @@ chunksize_store(struct mddev *mddev, conif (csize <512 || !is_power_of_2 (csize))return -EINVAL ; +if (BITS_PER_LONG >32 && csize >= (1ULL << (BITS_PER_BYTE * +sizeof (((bitmap_super_t *)0 )->chunksize)))) +return -EOVERFLOW ; mddev->bitmap_info.chunksize = csize;return len; }
Greg Kroah-Hartman
maintainerPATCH 509/658 efi: Add iMac Pro 2017 to uefi skip cert quirk
In reply to Greg Kroah-HartmanFrom: Aditya Garg <[email protected]>
commit 0be56a116220f9e5731a6609e66a11accfe8d8e2 upstream.
The iMac Pro 2017 is also a T2 Mac. Thus add it to the list of uefi skip cert.
--- security/integrity/platform_certs/load_uefi.c | 1 + 1 file changed, 1 insertion(+)
security/integrity/platform_certs/load_uefi.c +1 -0
@@ -34,6 +34,7 @@ static const struct dmi_system_id uefi_s { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "MacPro7,1") }, { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMac20,1") }, { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMac20,2") }, + { UEFI_QUIRK_SKIP_CERT("Apple Inc.", "iMacPro1,1") }, { } };
Greg Kroah-Hartman
maintainerPATCH 510/658 ipmi: fix long wait in unload when IPMI disconnect
In reply to Greg Kroah-HartmanFrom: Zhang Yuchen <[email protected]>
commit f6f1234d98cce69578bfac79df147a1f6660596c upstream.
When fixing the problem mentioned in PATCH1, we also found the following problem:
If the IPMI is disconnected and in the sending process, the uninstallation driver will be stuck for a long time.
The main problem is that uninstalling the driver waits for curr_msg to be sent or HOSED. After stopping tasklet, the only place to trigger the timeout mechanism is the circular poll in shutdown_smi.
The poll function delays 10us and calls smi_event_handler(smi_info,10). Smi_event_handler deducts 10us from kcs->ibf_timeout.
But the poll func is followed by schedule_timeout_uninterruptible(1). The time consumed here is not counted in kcs->ibf_timeout.
So when 10us is deducted from kcs->ibf_timeout, at least 1 jiffies has actually passed. The waiting time has increased by more than a hundredfold.
Now instead of calling poll(). call smi_event_handler() directly and calculate the elapsed time.
For verification, you can directly use ebpf to check the kcs-> ibf_timeout for each call to kcs_event() when IPMI is disconnected. Decrement at normal rate before unloading. The decrement rate becomes very slow after unloading.
$ bpftrace -e 'kprobe:kcs_event {printf("kcs->ibftimeout : %d\n",
*(arg0+584));}'Message-Id: <[email protected]>
--- drivers/char/ipmi/ipmi_si_intf.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/char/ipmi/ipmi_si_intf.c +19 -8
@@ -2157,6 +2157,20 @@ skip_fallback_noirq: }module_init (init_ipmi_si); +static void wait_msg_processed (struct smi_info *smi_info) +{ +unsigned long jiffies_now; +long time_diff; + +while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { + jiffies_now = jiffies; + time_diff = (((long )jiffies_now - (long )smi_info->last_timeout_jiffies) + *SI_USEC_PER_JIFFY ); +smi_event_handler (smi_info, time_diff); +schedule_timeout_uninterruptible (1 ); + } +} +static void shutdown_smi (void *send_info) {struct smi_info *smi_info = send_info;
@@ -2191,16 +2205,13 @@ static void shutdown_smi(void *send_info* in the BMC. Note that timers and CPU interrupts are off, * so no need for locks. */ -while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { -poll (smi_info); -schedule_timeout_uninterruptible (1 ); - } +wait_msg_processed (smi_info); +if (smi_info->handlers)disable_si_irq (smi_info); -while (smi_info->curr_msg || (smi_info->si_state !=SI_NORMAL )) { -poll (smi_info); -schedule_timeout_uninterruptible (1 ); - } + +wait_msg_processed (smi_info); +if (smi_info->handlers) smi_info->handlers->cleanup (smi_info->si_sm);
Greg Kroah-Hartman
maintainerPATCH 511/658 mtd: spi-nor: Check for zero erase size in spi_nor_find_best_erase_type()
In reply to Greg Kroah-HartmanFrom: Alexander Sverdlin <[email protected]>
commit 2ebc336be08160debfe27f87660cf550d710f3e9 upstream.
Erase can be zeroed in spi_nor_parse_4bait() or spi_nor_init_non_uniform_erase_map(). In practice it happened with mt25qu256a, which supports 4K, 32K, 64K erases with 3b address commands, but only 4K and 64K erase with 4b address commands.
--- drivers/mtd/spi-nor/spi-nor.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mtd/spi-nor/spi-nor.c +2 -0
@@ -1010,6 +1010,8 @@ spi_nor_find_best_erase_type(const struccontinue ; erase = &map->erase_type[i]; +if (!erase->size) +continue ;/* Alignment is not mandatory for overlaid regions */ if (region->offset & SNOR_OVERLAID_REGION &&
Greg Kroah-Hartman
maintainerPATCH 512/658 ima: Fix a potential NULL pointer access in ima_restore_measurement_list
In reply to Greg Kroah-HartmanFrom: Huaxin Lu <[email protected]>
commit 11220db412edae8dba58853238f53258268bdb88 upstream.
In restore_template_fmt, when kstrdup fails, a non-NULL value will still be returned, which causes a NULL pointer access in template_desc_init_fields.
--- security/integrity/ima/ima_template.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
security/integrity/ima/ima_template.c +4 -1
@@ -292,8 +292,11 @@ static struct ima_template_desc *restore template_desc->name ="" ; template_desc->fmt =kstrdup (template_name,GFP_KERNEL ); -if (!template_desc->fmt) +if (!template_desc->fmt) { +kfree (template_desc); + template_desc =NULL ; goto out; + }spin_lock (&template_list);list_add_tail_rcu (&template_desc->list, &defined_templates);
Greg Kroah-Hartman
maintainerPATCH 513/658 ipmi: fix use after free in _ipmi_destroy_user()
In reply to Greg Kroah-HartmanFrom: Dan Carpenter <[email protected]>
commit a92ce570c81dc0feaeb12a429b4bc65686d17967 upstream.
The intf_free() function frees the "intf" pointer so we cannot dereference it again on the next line.
Message-Id: <Y3M8xa1drZv4CToE@kili>
--- drivers/char/ipmi/ipmi_msghandler.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/ipmi/ipmi_msghandler.c +3 -1
@@ -1298,6 +1298,7 @@ static void _ipmi_destroy_user(struct ipunsigned long flags;struct cmd_rcvr *rcvr;struct cmd_rcvr *rcvrs =NULL ; +struct module *owner;if (!acquire_ipmi_user (user, &i)) {/*
@@ -1358,8 +1359,9 @@ static void _ipmi_destroy_user(struct ipkfree (rcvr); } + owner = intf->owner;kref_put (&intf->refcount, intf_free); -module_put (intf->owner); +module_put (owner); }int ipmi_destroy_user (struct ipmi_user *user)
Greg Kroah-Hartman
maintainerPATCH 514/658 PCI: Fix pci_device_is_present() for VFs by checking PF
In reply to Greg Kroah-HartmanFrom: Michael S. Tsirkin <[email protected]>
commit 98b04dd0b4577894520493d96bc4623387767445 upstream.
pci_device_is_present() previously didn't work for VFs because it reads the Vendor and Device ID, which are 0xffff for VFs, which looks like they aren't present. Check the PF instead.
Wei Gong reported that if virtio I/O is in progress when the driver is unbound or "0" is written to /sys/.../sriov_numvfs, the virtio I/O operation hangs, which may result in output like this:
task:bash state:D stack: 0 pid: 1773 ppid: 1241 flags:0x00004002
Call Trace: schedule+0x4f/0xc0 blk_mq_freeze_queue_wait+0x69/0xa0 blk_mq_freeze_queue+0x1b/0x20 blk_cleanup_queue+0x3d/0xd0 virtblk_remove+0x3c/0xb0 [virtio_blk] virtio_dev_remove+0x4b/0x80 ... device_unregister+0x1b/0x60 unregister_virtio_device+0x18/0x30 virtio_pci_remove+0x41/0x80 pci_device_remove+0x3e/0xb0
This happened because pci_device_is_present(VF) returned "false" in virtio_pci_remove(), so it called virtio_break_device(). The broken vq meant that vring_interrupt() skipped the vq.callback() that would have completed the virtio I/O operation via virtblk_done().
--- drivers/pci/pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pci/pci.c +2 -0
@@ -6093,6 +6093,8 @@ bool pci_device_is_present(struct pci_de {u32 v; +/* Check PF if pdev is a VF, since VF Vendor/Device IDs are 0xffff */ + pdev =pci_physfn (pdev);if (pci_dev_is_disconnected (pdev))return false;return pci_bus_read_dev_vendor_id (pdev->bus, pdev->devfn, &v,0 );
Greg Kroah-Hartman
maintainerPATCH 515/658 PCI/sysfs: Fix double free in error path
In reply to Greg Kroah-HartmanFrom: Sascha Hauer <[email protected]>
commit aa382ffa705bea9931ec92b6f3c70e1fdb372195 upstream.
When pci_create_attr() fails, pci_remove_resource_files() is called which will iterate over the res_attr[_wc] arrays and frees every non NULL entry. To avoid a double free here set the array entry only after it's clear we successfully initialized it.
--- drivers/pci/pci-sysfs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/pci/pci-sysfs.c +9 -4
@@ -1157,11 +1157,9 @@ static int pci_create_attr(struct pci_desysfs_bin_attr_init (res_attr);if (write_combine) { - pdev->res_attr_wc[num] = res_attr;sprintf (res_attr_name,"resource%d_wc" , num); res_attr->mmap = pci_mmap_resource_wc; }else { - pdev->res_attr[num] = res_attr;sprintf (res_attr_name,"resource%d" , num);if (pci_resource_flags (pdev, num) &IORESOURCE_IO ) { res_attr->read = pci_read_resource_io;
@@ -1177,10 +1175,17 @@ static int pci_create_attr(struct pci_de res_attr->size =pci_resource_len (pdev, num); res_attr->private = (void *)(unsigned long )num; retval =sysfs_create_bin_file (&pdev->dev.kobj, res_attr); -if (retval) +if (retval) {kfree (res_attr); +return retval; + } + +if (write_combine) + pdev->res_attr_wc[num] = res_attr; +else + pdev->res_attr[num] = res_attr; -return retval; +return 0 ; }/**
Greg Kroah-Hartman
maintainerPATCH 516/658 crypto: n2 - add missing hash statesize
In reply to Greg Kroah-HartmanFrom: Corentin Labbe <[email protected]>
commit 76a4e874593543a2dff91d249c95bac728df2774 upstream.
Add missing statesize to hash templates.
This is mandatory otherwise no algorithms can be registered as the core requires statesize to be set.
--- drivers/crypto/n2_core.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/crypto/n2_core.c +6 -0
@@ -1278,6 +1278,7 @@ struct n2_hash_tmpl {const u32 *hash_init;u8 hw_op_hashsz;u8 digest_size; +u8 statesize;u8 block_size;u8 auth_type;u8 hmac_type;
@@ -1309,6 +1310,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_MD5, .hw_op_hashsz = MD5_DIGEST_SIZE, .digest_size = MD5_DIGEST_SIZE, + .statesize = sizeof(struct md5_state), .block_size = MD5_HMAC_BLOCK_SIZE }, { .name = "sha1", .hash_zero = sha1_zero_message_hash,
@@ -1317,6 +1319,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_SHA1, .hw_op_hashsz = SHA1_DIGEST_SIZE, .digest_size = SHA1_DIGEST_SIZE, + .statesize = sizeof(struct sha1_state), .block_size = SHA1_BLOCK_SIZE }, { .name = "sha256", .hash_zero = sha256_zero_message_hash,
@@ -1325,6 +1328,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_HMAC_SHA256, .hw_op_hashsz = SHA256_DIGEST_SIZE, .digest_size = SHA256_DIGEST_SIZE, + .statesize = sizeof(struct sha256_state), .block_size = SHA256_BLOCK_SIZE }, { .name = "sha224", .hash_zero = sha224_zero_message_hash,
@@ -1333,6 +1337,7 @@ static const struct n2_hash_tmpl hash_tm .hmac_type = AUTH_TYPE_RESERVED, .hw_op_hashsz = SHA256_DIGEST_SIZE, .digest_size = SHA224_DIGEST_SIZE, + .statesize = sizeof(struct sha256_state), .block_size = SHA224_BLOCK_SIZE }, };#define NUM_HASH_TMPLS ARRAY_SIZE(hash_tmpls)
@@ -1474,6 +1479,7 @@ static int __n2_register_one_ahash(const halg = &ahash->halg; halg->digestsize = tmpl->digest_size; + halg->statesize = tmpl->statesize; base = &halg->base;snprintf (base->cra_name,CRYPTO_MAX_ALG_NAME ,"%s" , tmpl->name);
Greg Kroah-Hartman
maintainerPATCH 517/658 iommu/amd: Fix ivrs_acpihid cmdline parsing code
In reply to Greg Kroah-HartmanFrom: Kim Phillips <[email protected]>
commit 5f18e9f8868c6d4eae71678e7ebd4977b7d8c8cf upstream.
The second (UID) strcmp in acpi_dev_hid_uid_match considers "0" and "00" different, which can prevent device registration.
Have the AMD IOMMU driver's ivrs_acpihid parsing code remove any leading zeroes to make the UID strcmp succeed. Now users can safely specify "AMDxxxxx:00" or "AMDxxxxx:0" and expect the same behaviour.
--- drivers/iommu/amd_iommu_init.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/iommu/amd_iommu_init.c +7 -0
@@ -3051,6 +3051,13 @@ static int __init parse_ivrs_acpihid(chareturn 1 ; } +/* +* Ignore leading zeroes after ':', so e.g., AMDI0095:00 +* will match AMDI0095:0 in the second strcmp in acpi_dev_hid_uid_match +*/ +while (*uid =='0' && *(uid +1 )) + uid++; + i = early_acpihid_map_size++;memcpy (early_acpihid_map[i].hid, hid,strlen (hid));memcpy (early_acpihid_map[i].uid, uid,strlen (uid));
Greg Kroah-Hartman
maintainerPATCH 518/658 parisc: led: Fix potential null-ptr-deref in start_task()
In reply to Greg Kroah-HartmanFrom: Shang XiaoJing <[email protected]>
commit 41f563ab3c33698bdfc3403c7c2e6c94e73681e4 upstream.
start_task() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:
start_task()
create_singlethread_workqueue() # failed, led_wq is NULL queue_delayed_work()
queue_delayed_work_on()
__queue_delayed_work() # warning here, but continue
__queue_work() # access wq->flags, null-ptr-deref
Check the ret value and return -ENOMEM if it is NULL.
--- drivers/parisc/led.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/parisc/led.c +3 -0
@@ -137,6 +137,9 @@ static int start_task(void)/* Create the work queue and queue the LED task */ led_wq =create_singlethread_workqueue ("led_wq" ); +if (!led_wq) +return -ENOMEM ; +queue_delayed_work (led_wq, &led_task,0 );return 0 ;
Greg Kroah-Hartman
maintainerPATCH 519/658 device_cgroup: Roll back to original exceptions after copy failure
In reply to Greg Kroah-HartmanFrom: Wang Weiyang <[email protected]>
commit e68bfbd3b3c3a0ec3cf8c230996ad8cabe90322f upstream.
When add the 'a *:* rwm' entry to devcgroup A's whitelist, at first A's exceptions will be cleaned and A's behavior is changed to DEVCG_DEFAULT_ALLOW. Then parent's exceptions will be copyed to A's whitelist. If copy failure occurs, just return leaving A to grant permissions to all devices. And A may grant more permissions than parent.
Backup A's whitelist and recover original exceptions after copy failure.
--- security/device_cgroup.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
security/device_cgroup.c +29 -4
@@ -79,6 +79,17 @@ free_and_exit:return -ENOMEM ; } +static void dev_exceptions_move (struct list_head *dest,struct list_head *orig) +{ +struct dev_exception_item *ex, *tmp; + +lockdep_assert_held (&devcgroup_mutex); + +list_for_each_entry_safe (ex, tmp, orig, list) { +list_move_tail (&ex->list, dest); + } +} +/* * called under devcgroup_mutex */
@@ -601,11 +612,13 @@ static int devcgroup_update_access(strucint count, rc =0 ;struct dev_exception_item ex;struct dev_cgroup *parent =css_to_devcgroup (devcgroup->css.parent); +struct dev_cgroup tmp_devcgrp;if (!capable (CAP_SYS_ADMIN ))return -EPERM ;memset (&ex,0 ,sizeof (ex)); +memset (&tmp_devcgrp,0 ,sizeof (tmp_devcgrp)); b = buffer;switch (*b) {
@@ -617,15 +630,27 @@ static int devcgroup_update_access(strucif (!may_allow_all (parent))return -EPERM ; -dev_exception_clean (devcgroup); - devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; -if (!parent) +if (!parent) { + devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; +dev_exception_clean (devcgroup);break ; + } +INIT_LIST_HEAD (&tmp_devcgrp.exceptions); + rc =dev_exceptions_copy (&tmp_devcgrp.exceptions, + &devcgroup->exceptions); +if (rc) +return rc; +dev_exception_clean (devcgroup); rc =dev_exceptions_copy (&devcgroup->exceptions, &parent->exceptions); -if (rc) +if (rc) { +dev_exceptions_move (&devcgroup->exceptions, + &tmp_devcgrp.exceptions);return rc; + } + devcgroup->behavior =DEVCG_DEFAULT_ALLOW ; +dev_exception_clean (&tmp_devcgrp);break ;case DEVCG_DENY :if (css_has_online_children (&devcgroup->css))
Greg Kroah-Hartman
maintainerPATCH 520/658 drm/connector: send hotplug uevent on connector cleanup
In reply to Greg Kroah-HartmanFrom: Simon Ser <[email protected]>
commit 6fdc2d490ea1369d17afd7e6eb66fecc5b7209bc upstream.
A typical DP-MST unplug removes a KMS connector. However care must be taken to properly synchronize with user-space. The expected sequence of events is the following:
1. The kernel notices that the DP-MST port is gone.
2. The kernel marks the connector as disconnected, then sends a uevent to make user-space re-scan the connector list.
3. User-space notices the connector goes from connected to disconnected, disables it.
4. Kernel handles the IOCTL disabling the connector. On success, the very last reference to the struct drm_connector is dropped and drm_connector_cleanup() is called.
5. The connector is removed from the list, and a uevent is sent to tell user-space that the connector disappeared.
The very last step was missing. As a result, user-space thought the connector still existed and could try to disable it again. Since the kernel no longer knows about the connector, that would end up with EINVAL and confused user-space.
Fix this by sending a hotplug uevent from drm_connector_cleanup().
--- drivers/gpu/drm/drm_connector.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_connector.c +3 -0
@@ -474,6 +474,9 @@ void drm_connector_cleanup(struct drm_comutex_destroy (&connector->mutex);memset (connector,0 ,sizeof (*connector)); + +if (dev->registered) +drm_sysfs_hotplug_event (dev); }EXPORT_SYMBOL (drm_connector_cleanup);
Greg Kroah-Hartman
maintainerPATCH 521/658 drm/vmwgfx: Validate the box size for the snooped cursor
In reply to Greg Kroah-HartmanFrom: Zack Rusin <[email protected]>
commit 4cf949c7fafe21e085a4ee386bb2dade9067316e upstream.
Invalid userspace dma surface copies could potentially overflow the memcpy from the surface to the snooped image leading to crashes. To fix it the dimensions of the copybox have to be validated against the expected size of the snooped cursor.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +2 -1
@@ -182,7 +182,8 @@ void vmw_kms_cursor_snoop(struct vmw_surif (cmd->dma.guest.ptr.offset %PAGE_SIZE || box->x !=0 || box->y !=0 || box->z !=0 || box->srcx !=0 || box->srcy !=0 || box->srcz !=0 || - box->d !=1 || box_count !=1 ) { + box->d !=1 || box_count !=1 || + box->w >64 || box->h >64 ) {/* TODO handle none page aligned offsets */ /* TODO handle more dst & src != 0 */ /* TODO handle more then one copy */
Greg Kroah-Hartman
maintainerPATCH 522/658 ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit eee22187b53611e173161e38f61de1c7ecbeb876 upstream.
In do_writepages, if the value returned by ext4_writepages is "-ENOMEM" and "wbc->sync_mode == WB_SYNC_ALL", retry until the condition is not met.
In __ext4_get_inode_loc, if the bh returned by sb_getblk is NULL, the function returns -ENOMEM.
In __getblk_slow, if the return value of grow_buffers is less than 0, the function returns NULL.
When the three processes are connected in series like the following stack, an infinite loop may occur:
do_writepages <--- keep retrying
ext4_writepages
mpage_map_and_submit_extent
mpage_map_one_extent
ext4_map_blocks
ext4_ext_map_blocks
ext4_ext_handle_unwritten_extents
ext4_ext_convert_to_initialized
ext4_split_extent
ext4_split_extent_at
__ext4_ext_dirty
__ext4_mark_inode_dirty
ext4_reserve_inode_write
ext4_get_inode_loc
__ext4_get_inode_loc <--- return -ENOMEM
sb_getblk
__getblk_gfp
__getblk_slow <--- return NULL
grow_buffers
grow_dev_page <--- return -ENXIO
ret = (block < end_block) ? 1 : -ENXIO;In this issue, bg_inode_table_hi is overwritten as an incorrect value. As a result, block < end_block cannot be met in grow_dev_page. Therefore, __ext4_get_inode_loc always returns '-ENOMEM' and do_writepages keeps retrying. As a result, the writeback process is in the D state due to an infinite loop.
Add a check on inode table block in the __ext4_get_inode_loc function by referring to ext4_read_inode_bitmap to avoid this infinite loop.
--- fs/ext4/inode.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/ext4/inode.c +9 -1
@@ -4652,9 +4652,17 @@ static int __ext4_get_inode_loc(struct i inodes_per_block =EXT4_SB (sb)->s_inodes_per_block; inode_offset = ((inode->i_ino -1 ) %EXT4_INODES_PER_GROUP (sb)); - block =ext4_inode_table (sb, gdp) + (inode_offset / inodes_per_block); iloc->offset = (inode_offset % inodes_per_block) *EXT4_INODE_SIZE (sb); + block =ext4_inode_table (sb, gdp); +if ((block <=le32_to_cpu (EXT4_SB (sb)->s_es->s_first_data_block)) || + (block >=ext4_blocks_count (EXT4_SB (sb)->s_es))) { +ext4_error (sb,"Invalid inode table block %llu in " +"block_group %u" , block, iloc->block_group); +return -EFSCORRUPTED ; + } + block += (inode_offset / inodes_per_block); + bh =sb_getblk (sb, block);if (unlikely (!bh))return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 523/658 ext4: fix undefined behavior in bit shift for ext4_check_flag_values
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
commit 3bf678a0f9c017c9ba7c581541dbc8453452a7ae upstream.
Shifting signed 32-bit value by 31 bits is undefined, so changing significant bit to unsigned. The UBSAN warning calltrace like below:
UBSAN: shift-out-of-bounds in fs/ext4/ext4.h:591:2 left shift of 1 by 31 places cannot be represented in type 'int' Call Trace: <TASK> dump_stack_lvl+0x7d/0xa5 dump_stack+0x15/0x1b ubsan_epilogue+0xe/0x4e __ubsan_handle_shift_out_of_bounds+0x1e7/0x20c ext4_init_fs+0x5a/0x277 do_one_initcall+0x76/0x430 kernel_init_freeable+0x3b3/0x422 kernel_init+0x24/0x1e0 ret_from_fork+0x1f/0x30 </TASK>
--- fs/ext4/ext4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4.h +1 -1
@@ -501,7 +501,7 @@ enum {* * It's not paranoia if the Murphy's Law really *is* out to get you. :-) */ -#define TEST_FLAG_VALUE (FLAG ) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) +#define TEST_FLAG_VALUE (FLAG ) (EXT4_##FLAG##_FL == (1U << EXT4_INODE_##FLAG))#define CHECK_FLAG_VALUE (FLAG ) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG))static inline void ext4_check_flag_values (void )
Greg Kroah-Hartman
maintainerPATCH 524/658 ext4: add EXT4_IGET_BAD flag to prevent unexpected bad inode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 63b1e9bccb71fe7d7e3ddc9877dbdc85e5d2d023 upstream.
There are many places that will get unhappy (and crash) when ext4_iget() returns a bad inode. However, if iget the boot loader inode, allows a bad inode to be returned, because the inode may not be initialized. This mechanism can be used to bypass some checks and cause panic. To solve this problem, we add a special iget flag EXT4_IGET_BAD. Only with this flag we'd be returning bad inode from ext4_iget(), otherwise we always return the error code if the inode is bad inode.(suggested by Jan Kara)
--- fs/ext4/ext4.h | 3 ++- fs/ext4/inode.c | 8 +++++++- fs/ext4/ioctl.c | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-)
fs/ext4/ext4.h +2 -1
@@ -2608,7 +2608,8 @@ int do_journal_get_write_access(handle_ttypedef enum {EXT4_IGET_NORMAL =0 ,EXT4_IGET_SPECIAL =0x0001 ,/* OK to iget a system inode */ -EXT4_IGET_HANDLE =0x0002 /* Inode # is from a handle */ +EXT4_IGET_HANDLE =0x0002 ,/* Inode # is from a handle */ +EXT4_IGET_BAD =0x0004 /* Allow to iget a bad inode */ }ext4_iget_flags ; extern struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
fs/ext4/inode.c +7 -1
@@ -5192,8 +5192,14 @@ struct inode *__ext4_iget(struct super_bif (IS_CASEFOLDED (inode) && !ext4_has_feature_casefold (inode->i_sb))ext4_error_inode (inode, function, line,0 ,"casefold flag without casefold feature" ); -brelse (iloc.bh); +if (is_bad_inode (inode) && !(flags &EXT4_IGET_BAD )) { +ext4_error_inode (inode, function, line,0 , +"bad inode without EXT4_IGET_BAD flag" ); + ret = -EUCLEAN ; + goto bad_inode; + } +brelse (iloc.bh);unlock_new_inode (inode);return inode;
fs/ext4/ioctl.c +2 -1
@@ -121,7 +121,8 @@ static long swap_inode_boot_loader(strucblkcnt_t blocks;unsigned short bytes; - inode_bl =ext4_iget (sb,EXT4_BOOT_LOADER_INO ,EXT4_IGET_SPECIAL ); + inode_bl =ext4_iget (sb,EXT4_BOOT_LOADER_INO , +EXT4_IGET_SPECIAL |EXT4_IGET_BAD );if (IS_ERR (inode_bl))return PTR_ERR (inode_bl); ei_bl =EXT4_I (inode_bl);
Greg Kroah-Hartman
maintainerPATCH 525/658 ext4: add helper to check quota inums
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 07342ec259df2a35d6a34aebce010567a80a0e15 upstream.
Before quota is enabled, a check on the preset quota inums in ext4_super_block is added to prevent wrong quota inodes from being loaded. In addition, when the quota fails to be enabled, the quota type and quota inum are printed to facilitate fault locating.
--- fs/ext4/super.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
fs/ext4/super.c +25 -3
@@ -5954,6 +5954,20 @@ static int ext4_quota_on(struct super_blreturn err; } +static inline bool ext4_check_quota_inum (int type,unsigned long qf_inum) +{ +switch (type) { +case USRQUOTA : +return qf_inum ==EXT4_USR_QUOTA_INO ; +case GRPQUOTA : +return qf_inum ==EXT4_GRP_QUOTA_INO ; +case PRJQUOTA : +return qf_inum >=EXT4_GOOD_OLD_FIRST_INO ; +default : +BUG (); + } +} +static int ext4_quota_enable (struct super_block *sb,int type,int format_id,unsigned int flags) {
@@ -5970,9 +5984,16 @@ static int ext4_quota_enable(struct supeif (!qf_inums[type])return -EPERM ; +if (!ext4_check_quota_inum (type, qf_inums[type])) { +ext4_error (sb,"Bad quota inum: %lu, type: %d" , + qf_inums[type], type); +return -EUCLEAN ; + } + qf_inode =ext4_iget (sb, qf_inums[type],EXT4_IGET_SPECIAL );if (IS_ERR (qf_inode)) { -ext4_error (sb,"Bad quota inode # %lu" , qf_inums[type]); +ext4_error (sb,"Bad quota inode: %lu, type: %d" , + qf_inums[type], type);return PTR_ERR (qf_inode); }
@@ -6011,8 +6032,9 @@ static int ext4_enable_quotas(struct supif (err) {ext4_warning (sb,"Failed to enable quota tracking " -"(type=%d, err=%d). Please run " -"e2fsck to fix." , type, err); +"(type=%d, err=%d, ino=%lu). " +"Please run e2fsck to fix." , type, + err, qf_inums[type]);for (type--; type >=0 ; type--) {struct inode *inode;
Greg Kroah-Hartman
maintainerPATCH 526/658 ext4: fix reserved cluster accounting in __es_remove_extent()
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit 1da18e38cb97e9521e93d63034521a9649524f64 upstream.
When bigalloc is enabled, reserved cluster accounting for delayed allocation is handled in extent_status.c. With a corrupted file system, it's possible for this accounting to be incorrect, dsicovered by Syzbot:
EXT4-fs error (device loop0): ext4_validate_block_bitmap:398: comm rep:
bg 0: block 5: invalid block bitmap
EXT4-fs (loop0): Delayed block allocation failed for inode 18 at logical
offset 0 with max blocks 32 with error 28
EXT4-fs (loop0): This should not happen!! Data will be lost
EXT4-fs (loop0): Total free blocks count 0
EXT4-fs (loop0): Free/Dirty block details
EXT4-fs (loop0): free_blocks=0
EXT4-fs (loop0): dirty_blocks=32
EXT4-fs (loop0): Block reservation details
EXT4-fs (loop0): i_reserved_data_blocks=2
EXT4-fs (loop0): Inode 18 (00000000845cd634):
i_reserved_data_blocks (1) not cleared!
Above issue happens as follows:
Assume:sbi->s_cluster_ratio = 16
Step1:
Insert delay block [0, 31] -> ei->i_reserved_data_blocks=2 Step2:ext4_writepages
mpage_map_and_submit_extent -> return failed mpage_release_unused_pages -> to release [0, 30]
ext4_es_remove_extent -> remove lblk=0 end=30
__es_remove_extent -> len1=0 len2=31-30=1
__es_remove_extent:
...
if (len2 > 0) {
...
if (len1 > 0) {
...
} else {
es->es_lblk = end + 1;
es->es_len = len2;
...
}
if (count_reserved)
count_rsvd(inode, lblk, ...);
goto out; -> will return but didn't calculate 'reserved' ...
Step3:ext4_destroy_inode -> trigger "i_reserved_data_blocks (1) not cleared!"
To solve above issue if 'len2>0' call 'get_rsvd()' before goto out.
--- fs/ext4/extents_status.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/extents_status.c +2 -1
@@ -1354,7 +1354,7 @@ retry:if (count_reserved)count_rsvd (inode, lblk, orig_es.es_len - len1 - len2, &orig_es, &rc); - goto out; + goto out_get_reserved; }if (len1 >0 ) {
@@ -1396,6 +1396,7 @@ retry: } } +out_get_reserved:if (count_reserved) *reserved =get_rsvd (inode, end, es, &rc); out:
Greg Kroah-Hartman
maintainerPATCH 527/658 ext4: fix bug_on in __es_tree_search caused by bad boot loader inode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 991ed014de0840c5dc405b679168924afb2952ac upstream.
We got a issue as fllows:
==================================================================
kernel BUG at fs/ext4/extents_status.c:203!
invalid opcode: 0000 [#1] PREEMPT SMP
CPU: 1 PID: 945 Comm: cat Not tainted 6.0.0-next-20221007-dirty #349 RIP: 0010:ext4_es_end.isra.0+0x34/0x42 RSP: 0018:ffffc9000143b768 EFLAGS: 00010203 RAX: 0000000000000000 RBX: ffff8881769cd0b8 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffffff8fc27cf7 RDI: 00000000ffffffff RBP: ffff8881769cd0bc R08: 0000000000000000 R09: ffffc9000143b5f8 R10: 0000000000000001 R11: 0000000000000001 R12: ffff8881769cd0a0 R13: ffff8881768e5668 R14: 00000000768e52f0 R15: 0000000000000000 FS: 00007f359f7f05c0(0000)GS:ffff88842fd00000(0000)knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f359f5a2000 CR3: 000000017130c000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> __es_tree_search.isra.0+0x6d/0xf5 ext4_es_cache_extent+0xfa/0x230 ext4_cache_extents+0xd2/0x110 ext4_find_extent+0x5d5/0x8c0 ext4_ext_map_blocks+0x9c/0x1d30 ext4_map_blocks+0x431/0xa50 ext4_mpage_readpages+0x48e/0xe40 ext4_readahead+0x47/0x50 read_pages+0x82/0x530 page_cache_ra_unbounded+0x199/0x2a0 do_page_cache_ra+0x47/0x70 page_cache_ra_order+0x242/0x400 ondemand_readahead+0x1e8/0x4b0 page_cache_sync_ra+0xf4/0x110 filemap_get_pages+0x131/0xb20 filemap_read+0xda/0x4b0 generic_file_read_iter+0x13a/0x250 ext4_file_read_iter+0x59/0x1d0 vfs_read+0x28f/0x460 ksys_read+0x73/0x160 __x64_sys_read+0x1e/0x30 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd </TASK> ==================================================================
In the above issue, ioctl invokes the swap_inode_boot_loader function to swap inode<5> and inode<12>. However, inode<5> contain incorrect imode and disordered extents, and i_nlink is set to 1. The extents check for inode in the ext4_iget function can be bypassed bacause 5 is EXT4_BOOT_LOADER_INO. While links_count is set to 1, the extents are not initialized in swap_inode_boot_loader. After the ioctl command is executed successfully, the extents are swapped to inode<12>, in this case, run the cat command to view inode<12>. And Bug_ON is triggered due to the incorrect extents.
When the boot loader inode is not initialized, its imode can be one of the following:
1) the imode is a bad type, which is marked as bad_inode in ext4_iget and set to S_IFREG.
2) the imode is good type but not S_IFREG.
3) the imode is S_IFREG.
The BUG_ON may be triggered by bypassing the check in cases 1 and 2. Therefore, when the boot loader inode is bad_inode or its imode is not S_IFREG, initialize the inode to avoid triggering the BUG.
--- fs/ext4/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ioctl.c +1 -1
@@ -170,7 +170,7 @@ static long swap_inode_boot_loader(struc/* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem (inode, inode_bl); -if (inode_bl->i_nlink ==0 ) { +if (is_bad_inode (inode_bl) || !S_ISREG (inode_bl->i_mode)) {/* this inode has never been used as a BOOT_LOADER */ set_nlink (inode_bl,1 );i_uid_write (inode_bl,0 );
Greg Kroah-Hartman
maintainerPATCH 528/658 ext4: init quota for old.inode in ext4_rename
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit fae381a3d79bb94aa2eb752170d47458d778b797 upstream.
Syzbot found the following issue:ext4_parse_param: s_want_extra_isize=128ext4_inode_info_init: s_want_extra_isize=32ext4_rename: old.inode=ffff88823869a2c8 old.dir=ffff888238699828 new.inode=ffff88823869d7e8 new.dir=ffff888238699828 __ext4_mark_inode_dirty: inode=ffff888238699828 ea_isize=32 want_ea_size=128 __ext4_mark_inode_dirty: inode=ffff88823869a2c8 ea_isize=32 want_ea_size=128ext4_xattr_block_set: inode=ffff88823869a2c8
------------[ cut here ]------------ WARNING: CPU: 13 PID: 2234 at fs/ext4/xattr.c:2070 ext4_xattr_block_set.cold+0x22/0x980 Modules linked in: RIP: 0010:ext4_xattr_block_set.cold+0x22/0x980 RSP: 0018:ffff888227d3f3b0 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff88823007a000 RCX: 0000000000000000 RDX: 0000000000000a03 RSI: 0000000000000040 RDI: ffff888230078178 RBP: 0000000000000000 R08: 000000000000002c R09: ffffed1075c7df8e R10: ffff8883ae3efc6b R11: ffffed1075c7df8d R12: 0000000000000000 R13: ffff88823869a2c8 R14: ffff8881012e0460 R15: dffffc0000000000 FS: 00007f350ac1f740(0000) GS:ffff8883ae200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f350a6ed6a0 CR3: 0000000237456000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> ? ext4_xattr_set_entry+0x3b7/0x2320 ? ext4_xattr_block_set+0x0/0x2020 ? ext4_xattr_set_entry+0x0/0x2320 ? ext4_xattr_check_entries+0x77/0x310 ? ext4_xattr_ibody_set+0x23b/0x340 ext4_xattr_move_to_block+0x594/0x720 ext4_expand_extra_isize_ea+0x59a/0x10f0 __ext4_expand_extra_isize+0x278/0x3f0 __ext4_mark_inode_dirty.cold+0x347/0x410 ext4_rename+0xed3/0x174f vfs_rename+0x13a7/0x2510 do_renameat2+0x55d/0x920 __x64_sys_rename+0x7d/0xb0 do_syscall_64+0x3b/0xa0 entry_SYSCALL_64_after_hwframe+0x72/0xdc
As 'ext4_rename' will modify 'old.inode' ctime and mark inode dirty, which may trigger expand 'extra_isize' and allocate block. If inode didn't init quota will lead to warning. To solve above issue, init 'old.inode' firstly in 'ext4_rename'.
--- fs/ext4/namei.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext4/namei.c +3 -0
@@ -3780,6 +3780,9 @@ static int ext4_rename(struct inode *old retval =dquot_initialize (old.dir);if (retval)return retval; + retval =dquot_initialize (old.inode); +if (retval) +return retval; retval =dquot_initialize (new.dir);if (retval)return retval;
Greg Kroah-Hartman
maintainerPATCH 529/658 ext4: fix delayed allocation bug in ext4_clu_mapped for bigalloc + inline
In reply to Greg Kroah-HartmanFrom: Eric Whitney <[email protected]>
commit 131294c35ed6f777bd4e79d42af13b5c41bf2775 upstream.
When converting files with inline data to extents, delayed allocations made on a file system created with both the bigalloc and inline options can result in invalid extent status cache content, incorrect reserved cluster counts, kernel memory leaks, and potential kernel panics.
With bigalloc, the code that determines whether a block must be delayed allocated searches the extent tree to see if that block maps to a previously allocated cluster. If not, the block is delayed allocated, and otherwise, it isn't. However, if the inline option is also used, and if the file containing the block is marked as able to store data inline, there isn't a valid extent tree associated with the file. The current code in ext4_clu_mapped() calls ext4_find_extent() to search the non-existent tree for a previously allocated cluster anyway, which typically finds nothing, as desired. However, a side effect of the search can be to cache invalid content from the non-existent tree (garbage) in the extent status tree, including bogus entries in the pending reservation tree.
To fix this, avoid searching the extent tree when allocating blocks for bigalloc + inline files that are being converted from inline to extent mapped.
--- fs/ext4/extents.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ext4/extents.c +8 -0
@@ -6022,6 +6022,14 @@ int ext4_clu_mapped(struct inode *inode,struct ext4_extent *extent;ext4_lblk_t first_lblk, first_lclu, last_lclu; +/* +* if data can be stored inline, the logical cluster isn't +* mapped - no physical clusters have been allocated, and the +* file has no extents +*/ +if (ext4_test_inode_state (inode,EXT4_STATE_MAY_INLINE_DATA )) +return 0 ; +/* search for the extent closest to the first block in the cluster */ path =ext4_find_extent (inode,EXT4_C2B (sbi, lclu),NULL ,0 );if (IS_ERR (path)) {
Greg Kroah-Hartman
maintainerPATCH 530/658 ext4: fix corruption when online resizing a 1K bigalloc fs
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 0aeaa2559d6d53358fca3e3fce73807367adca74 upstream.
When a backup superblock is updated in update_backups(), the primary superblock's offset in the group (that is, sbi->s_sbh->b_blocknr) is used as the backup superblock's offset in its group. However, when the block size is 1K and bigalloc is enabled, the two offsets are not equal. This causes the backup group descriptors to be overwritten by the superblock in update_backups(). Moreover, if meta_bg is enabled, the file system will be corrupted because this feature uses backup group descriptors.
To solve this issue, we use a more accurate ext4_group_first_block_no() as the offset of the backup superblock in its group.
--- fs/ext4/resize.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ext4/resize.c +3 -3
@@ -1567,8 +1567,8 @@ exit_journal:int meta_bg =ext4_has_feature_meta_bg (sb);sector_t old_gdb =0 ; -update_backups (sb, sbi->s_sbh->b_blocknr, (char *)es, -sizeof (struct ext4_super_block ),0 ); +update_backups (sb,ext4_group_first_block_no (sb,0 ), + (char *)es,sizeof (struct ext4_super_block ),0 );for (; gdb_num <= gdb_num_end; gdb_num++) {struct buffer_head *gdb_bh;
@@ -1775,7 +1775,7 @@ errout:if (test_opt (sb,DEBUG ))printk (KERN_DEBUG "EXT4-fs: extended group to %llu " "blocks\n" ,ext4_blocks_count (es)); -update_backups (sb,EXT4_SB (sb)->s_sbh->b_blocknr, +update_backups (sb,ext4_group_first_block_no (sb,0 ), (char *)es,sizeof (struct ext4_super_block ),0 ); }return err;
Greg Kroah-Hartman
maintainerPATCH 531/658 ext4: fix error code return to user-space in ext4_get_branch()
In reply to Greg Kroah-HartmanFrom: Luís Henriques <[email protected]>
commit 26d75a16af285a70863ba6a81f85d81e7e65da50 upstream.
If a block is out of range in ext4_get_branch(), -ENOMEM will be returned to user-space. Obviously, this error code isn't really useful. This patch fixes it by making sure the right error code (-EFSCORRUPTED) is propagated to user-space. EUCLEAN is more informative than ENOMEM.
--- fs/ext4/indirect.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/ext4/indirect.c +8 -1
@@ -148,6 +148,7 @@ static Indirect *ext4_get_branch(structstruct super_block *sb = inode->i_sb;Indirect *p = chain;struct buffer_head *bh; +unsigned int key;int ret = -EIO ; *err =0 ;
@@ -156,7 +157,13 @@ static Indirect *ext4_get_branch(structif (!p->key) goto no_block;while (--depth) { - bh =sb_getblk (sb,le32_to_cpu (p->key)); + key =le32_to_cpu (p->key); +if (key >ext4_blocks_count (EXT4_SB (sb)->s_es)) { +/* the block was out of range */ + ret = -EFSCORRUPTED ; + goto failure; + } + bh =sb_getblk (sb, key);if (unlikely (!bh)) { ret = -ENOMEM ; goto failure;
Greg Kroah-Hartman
maintainerPATCH 532/658 ext4: avoid BUG_ON when creating xattrs
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit b40ebaf63851b3a401b0dc9263843538f64f5ce6 upstream.
Commit fb0a387dcdcd ("ext4: limit block allocations for indirect-block files to < 2^32") added code to try to allocate xattr block with 32-bit block number for indirect block based files on the grounds that these files cannot use larger block numbers. It also added BUG_ON when allocated block could not fit into 32 bits. This is however bogus reasoning because xattr block is stored in inode->i_file_acl and inode->i_file_acl_hi and as such even indirect block based files can happily use full 48 bits for xattr block number. The proper handling seems to be there basically since 64-bit block number support was added. So remove the bogus limitation and BUG_ON.
--- fs/ext4/xattr.c | 8 -------- 1 file changed, 8 deletions(-)
fs/ext4/xattr.c +0 -8
@@ -2066,19 +2066,11 @@ inserted: goal =ext4_group_first_block_no (sb,EXT4_I (inode)->i_block_group); - -/* non-extent files can't have physical blocks past 2^32 */ -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) - goal = goal &EXT4_MAX_BLOCK_FILE_PHYS ; - block =ext4_new_meta_blocks (handle, inode, goal,0 ,NULL , &error);if (error) goto cleanup; -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) -BUG_ON (block >EXT4_MAX_BLOCK_FILE_PHYS ); -ea_idebug (inode,"creating block %llu" , (unsigned long long )block);
Greg Kroah-Hartman
maintainerPATCH 533/658 ext4: fix inode leak in ext4_xattr_inode_create() on an error path
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit e4db04f7d3dbbe16680e0ded27ea2a65b10f766a upstream.
There is issue as follows when do setxattr with inject fault:
[localhost]# fsck.ext4 -fn /dev/sda
e2fsck 1.46.6-rc1 (12-Sep-2022)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Unattached zero-length inode 15. Clear? no
Unattached inode 15
Connect to /lost+found? no
Pass 5: Checking group summary information
/dev/sda: ********** WARNING: Filesystem still has errors **********
/dev/sda: 15/655360 files (0.0% non-contiguous), 66755/2621440 blocks
This occurs in 'ext4_xattr_inode_create()'. If 'ext4_mark_inode_dirty()' fails, dropping i_nlink of the inode is needed. Or will lead to inode leak.
--- fs/ext4/xattr.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext4/xattr.c +3 -0
@@ -1442,6 +1442,9 @@ static struct inode *ext4_xattr_inode_crif (!err) err =ext4_inode_attach_jinode (ea_inode);if (err) { +if (ext4_xattr_inode_dec_ref (handle, ea_inode)) +ext4_warning_inode (ea_inode, +"cleanup dec ref error %d" , err);iput (ea_inode);return ERR_PTR (err); }
Greg Kroah-Hartman
maintainerPATCH 534/658 ext4: initialize quota before expanding inode in setproject ioctl
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit 1485f726c6dec1a1f85438f2962feaa3d585526f upstream.
Make sure we initialize quotas before possibly expanding inode space (and thus maybe needing to allocate external xattr block) in ext4_ioctl_setproject(). This prevents not accounting the necessary block allocation.
--- fs/ext4/ioctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ext4/ioctl.c +4 -4
@@ -461,6 +461,10 @@ static int ext4_ioctl_setproject(structif (ext4_is_quota_file (inode))return err; + err =dquot_initialize (inode); +if (err) +return err; + err =ext4_get_inode_loc (inode, &iloc);if (err)return err;
@@ -476,10 +480,6 @@ static int ext4_ioctl_setproject(structbrelse (iloc.bh); } - err =dquot_initialize (inode); -if (err) -return err; - handle =ext4_journal_start (inode,EXT4_HT_QUOTA ,EXT4_QUOTA_INIT_BLOCKS (sb) +EXT4_QUOTA_DEL_BLOCKS (sb) +3 );
Greg Kroah-Hartman
maintainerPATCH 535/658 ext4: avoid unaccounted block allocation when expanding inode
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit 8994d11395f8165b3deca1971946f549f0822630 upstream.
When expanding inode space in ext4_expand_extra_isize_ea() we may need to allocate external xattr block. If quota is not initialized for the inode, the block allocation will not be accounted into quota usage. Make sure the quota is initialized before we try to expand inode space.
--- fs/ext4/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ext4/inode.c +8 -0
@@ -6059,6 +6059,14 @@ static int __ext4_expand_extra_isize(strreturn 0 ; } +/* +* We may need to allocate external xattr block so we need quotas +* initialized. Here we can be called with various locks held so we +* cannot affort to initialize quotas ourselves. So just bail. +*/ +if (dquot_initialize_needed (inode)) +return -EAGAIN ; +/* try to expand with EAs present */ error =ext4_expand_extra_isize_ea (inode, new_extra_isize, raw_inode, handle);
Greg Kroah-Hartman
maintainerPATCH 536/658 ext4: allocate extended attribute value in vmalloc area
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit cc12a6f25e07ed05d5825a1664b67a970842b2ca upstream.
Now, extended attribute value maximum length is 64K. The memory requested here does not need continuous physical addresses, so it is appropriate to use kvmalloc to request memory. At the same time, it can also cope with the situation that the extended attribute will become longer in the future.
--- fs/ext4/xattr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/xattr.c +2 -2
@@ -2566,7 +2566,7 @@ static int ext4_xattr_move_to_block(hand is =kzalloc (sizeof (struct ext4_xattr_ibody_find ),GFP_NOFS ); bs =kzalloc (sizeof (struct ext4_xattr_block_find ),GFP_NOFS ); - buffer =kmalloc (value_size,GFP_NOFS ); + buffer =kvmalloc (value_size,GFP_NOFS ); b_entry_name =kmalloc (entry->e_name_len +1 ,GFP_NOFS );if (!is || !bs || !buffer || !b_entry_name) { error = -ENOMEM ;
@@ -2618,7 +2618,7 @@ static int ext4_xattr_move_to_block(hand error =0 ; out:kfree (b_entry_name); -kfree (buffer); +kvfree (buffer);if (is)brelse (is->iloc.bh);if (bs)
Greg Kroah-Hartman
maintainerPATCH 537/658 drm/amdgpu: make display pinning more flexible (v2)
In reply to Greg Kroah-HartmanFrom: Alex Deucher <[email protected]>
commit 81d0bcf9900932633d270d5bc4a54ff599c6ebdb upstream.
Only apply the static threshold for Stoney and Carrizo. This hardware has certain requirements that don't allow mixing of GTT and VRAM. Newer asics do not have these requirements so we should be able to be more flexible with where buffers end up.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
@@ -1458,7 +1458,8 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_buint32_t amdgpu_bo_get_preferred_pin_domain (struct amdgpu_device *adev,uint32_t domain) { -if (domain == (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) { +if ((domain == (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) && + ((adev->asic_type ==CHIP_CARRIZO ) || (adev->asic_type ==CHIP_STONEY ))) { domain =AMDGPU_GEM_DOMAIN_VRAM ;if (adev->gmc.real_vram_size <=AMDGPU_SG_THRESHOLD ) domain =AMDGPU_GEM_DOMAIN_GTT ;
RE: [PATCH 5.4 537/658] drm/amdgpu: make display pinning more flexible (v2)
[Public]
Quoted 20 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Monday, January 16, 2023 10:50 AM
To: [email protected]
Cc: Greg Kroah-Hartman <[email protected]>; [email protected]; Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH 5.4 537/658] drm/amdgpu: make display pinning more flexible (v2)From: Alex Deucher <[email protected]>
commit
81d0bcf9900932633d270d5bc4a54ff599c6ebdbupstream.Only apply the static threshold for Stoney and Carrizo.
This hardware has certain requirements that don't allow mixing of GTT and VRAM. Newer asics do not have these requirements so we should be able to be more flexible with where buffers end up.
Quoted 8 lines
Acked-by Luben Tuikov <[email protected]>Reviewed-by Christian König <[email protected]>Signed-off-by Alex Deucher <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Let's drop this patch. There are regressions for hibernation on some platforms on kernels older than 6.1.x
Alex
Quoted 21 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -1458,7 +1458,8 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_b
uint32_tamdgpu_bo_get_preferred_pin_domain(structamdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-1uint32_t domain) { - if (domain == (AMDGPU_GEM_DOMAIN_VRAM |
AMDGPU_GEM_DOMAIN_GTT)) {drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-0+ if ((domain == (AMDGPU_GEM_DOMAIN_VRAM |
AMDGPU_GEM_DOMAIN_GTT)) &&drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-0+ ((adev->asic_type == CHIP_CARRIZO) || (adev->asic_type == +CHIP_STONEY))) { domain =AMDGPU_GEM_DOMAIN_VRAM ;if (adev->gmc.real_vram_size <=AMDGPU_SG_THRESHOLD ) domain =AMDGPU_GEM_DOMAIN_GTT ;
Greg Kroah-Hartman
maintainerRe: [PATCH 5.4 537/658] drm/amdgpu: make display pinning more flexible (v2)
Quoted 31 lines · Alexander
[Public]
Quoted 20 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Monday, January 16, 2023 10:50 AM
To: [email protected]
Cc: Greg Kroah-Hartman <[email protected]>; [email protected]; Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH 5.4 537/658] drm/amdgpu: make display pinning more flexible (v2)From: Alex Deucher <[email protected]>
commit
81d0bcf9900932633d270d5bc4a54ff599c6ebdbupstream.Only apply the static threshold for Stoney and Carrizo.
This hardware has certain requirements that don't allow mixing of GTT and VRAM. Newer asics do not have these requirements so we should be able to be more flexible with where buffers end up.Quoted 8 lines
Acked-by Luben Tuikov <[email protected]>Reviewed-by Christian König <[email protected]>Signed-off-by Alex Deucher <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 1 line
Let's drop this patch. There are regressions for hibernation on some platforms on kernels older than 6.1.x
Ok, is there a revert anywhere for the 5.10 and 5.15 releases that already have this in it? I'll go drop it from the remaining queues now.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerPATCH 538/658 btrfs: replace strncpy() with strscpy()
In reply to Greg Kroah-Hartman[ Upstream commit 63d5429f68a3d4c4aa27e65a05196c17f86c41d6 ]
Using strncpy() on NUL-terminated strings are deprecated. To avoid possible forming of non-terminated string strscpy() should be used.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- fs/btrfs/ioctl.c | 9 +++------ fs/btrfs/rcu-string.h | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-)
fs/btrfs/ioctl.c +3 -6
@@ -3299,13 +3299,10 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info, di_args->bytes_used =btrfs_device_get_bytes_used (dev); di_args->total_bytes =btrfs_device_get_total_bytes (dev);memcpy (di_args->uuid, dev->uuid,sizeof (di_args->uuid)); -if (dev->name) { -strncpy (di_args->path,rcu_str_deref (dev->name), -sizeof (di_args->path) -1 ); - di_args->path[sizeof (di_args->path) -1 ] =0 ; - }else { +if (dev->name) +strscpy (di_args->path,rcu_str_deref (dev->name),sizeof (di_args->path)); +else di_args->path[0 ] ='\0' ; - } out:rcu_read_unlock ();
fs/btrfs/rcu-string.h +5 -1
@@ -18,7 +18,11 @@ static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t mask) (len * sizeof(char)), mask);if (!ret)return ret; -strncpy (ret->str, src, len); +/* Warn if the source got unexpectedly truncated. */ +if (WARN_ON (strscpy (ret->str, src, len) <0 )) { +kfree (ret); +return NULL ; + }return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 539/658 PM/devfreq: governor: Add a private governor_data for governor
In reply to Greg Kroah-HartmanFrom: Kant Fan <[email protected]>
[ Upstream commit 5fdded8448924e3631d466eea499b11606c43640 ]
The member void *data in the structure devfreq can be overwrite by governor_userspace. For example:
1. The device driver assigned the devfreq governor to simple_ondemand by the function devfreq_add_device() and init the devfreq member void *data to a pointer of a static structure devfreq_simple_ondemand_data by the function devfreq_add_device().
2. The user changed the devfreq governor to userspace by the command "echo userspace > /sys/class/devfreq/.../governor".
3. The governor userspace alloced a dynamic memory for the struct userspace_data and assigend the member void *data of devfreq to this memory by the function userspace_init().
4. The user changed the devfreq governor back to simple_ondemand by the command "echo simple_ondemand > /sys/class/devfreq/.../governor".
5. The governor userspace exited and assigned the member void *data in the structure devfreq to NULL by the function userspace_exit().
6. The governor simple_ondemand fetched the static information of devfreq_simple_ondemand_data in the function devfreq_simple_ondemand_func() but the member void *data of devfreq was assigned to NULL by the function userspace_exit().
7. The information of upthreshold and downdifferential is lost and the governor simple_ondemand can't work correctly.
The member void *data in the structure devfreq is designed for a static pointer used in a governor and inited by the function devfreq_add_device(). This patch add an element named governor_data in the devfreq structure which can be used by a governor(E.g userspace) who want to assign a private data to do some private things.
--- drivers/devfreq/devfreq.c | 6 ++---- drivers/devfreq/governor_userspace.c | 12 ++++++------ include/linux/devfreq.h | 11 ++++++----- 3 files changed, 14 insertions(+), 15 deletions(-)
drivers/devfreq/devfreq.c +2 -4
@@ -603,8 +603,7 @@ static void devfreq_dev_release(struct device *dev)* @dev: the device to add devfreq feature. * @profile: device-specific profile to run devfreq. * @governor_name: name of the policy to choose frequency. -* @data: private data for the governor. The devfreq framework does not -* touch this value. +* @data: devfreq driver pass to governors, governor should not change it. */ struct devfreq *devfreq_add_device(struct device *dev, struct devfreq_dev_profile *profile,
@@ -788,8 +787,7 @@ static void devm_devfreq_dev_release(struct device *dev, void *res)* @dev: the device to add devfreq feature. * @profile: device-specific profile to run devfreq. * @governor_name: name of the policy to choose frequency. -* @data: private data for the governor. The devfreq framework does not -* touch this value. +* @data: devfreq driver pass to governors, governor should not change it. * * This function manages automatically the memory of devfreq device using device * resource management and simplify the free operation for memory of devfreq
drivers/devfreq/governor_userspace.c +6 -6
@@ -21,7 +21,7 @@ struct userspace_data {static int devfreq_userspace_func (struct devfreq *df,unsigned long *freq) { -struct userspace_data *data = df->data; +struct userspace_data *data = df->governor_data;if (data->valid) *freq = data->user_frequency;
@@ -40,7 +40,7 @@ static ssize_t store_freq(struct device *dev, struct device_attribute *attr,int err =0 ;mutex_lock (&devfreq->lock); - data = devfreq->data; + data = devfreq->governor_data;sscanf (buf,"%lu" , &wanted); data->user_frequency = wanted;
@@ -60,7 +60,7 @@ static ssize_t show_freq(struct device *dev, struct device_attribute *attr,int err =0 ;mutex_lock (&devfreq->lock); - data = devfreq->data; + data = devfreq->governor_data;if (data->valid) err =sprintf (buf,"%lu\n" , data->user_frequency);
@@ -91,7 +91,7 @@ static int userspace_init(struct devfreq *devfreq) goto out; } data->valid = false; - devfreq->data = data; + devfreq->governor_data = data; err =sysfs_create_group (&devfreq->dev.kobj, &dev_attr_group); out:
@@ -107,8 +107,8 @@ static void userspace_exit(struct devfreq *devfreq)if (devfreq->dev.kobj.sd)sysfs_remove_group (&devfreq->dev.kobj, &dev_attr_group); -kfree (devfreq->data); - devfreq->data =NULL ; +kfree (devfreq->governor_data); + devfreq->governor_data =NULL ; } static int devfreq_userspace_handler(struct devfreq *devfreq,
include/linux/devfreq.h +6 -5
@@ -121,10 +121,10 @@ struct devfreq_dev_profile {* devfreq.nb to the corresponding register notifier call chain. * @work: delayed work for load monitoring. * @previous_freq: previously configured frequency value. -* @data: Private data of the governor. The devfreq framework does not -* touch this. -* @min_freq: Limit minimum frequency requested by user (0: none) -* @max_freq: Limit maximum frequency requested by user (0: none) +* @data: devfreq driver pass to governors, governor should not change it. +* @governor_data: private data for governors, devfreq core doesn't touch it. +* @min_freq: Limit minimum frequency requested by user (0: none) +* @max_freq: Limit maximum frequency requested by user (0: none) * @scaling_min_freq: Limit minimum frequency requested by OPP interface * @scaling_max_freq: Limit maximum frequency requested by OPP interface * @stop_polling: devfreq polling status of a device.
@@ -159,7 +159,8 @@ struct devfreq {unsigned long previous_freq;struct devfreq_dev_status last_status; -void *data;/* private data for governors */ +void *data; +void *governor_data;unsigned long min_freq;unsigned long max_freq;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 540/658 media: s5p-mfc: Fix to handle reference queue during finishing
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit d8a46bc4e1e0446459daa77c4ce14218d32dacf9 ]
On receiving last buffer driver puts MFC to MFCINST_FINISHING state which in turn skips transferring of frame from SRC to REF queue. This causes driver to stop MFC encoding and last frame is lost.
This patch guarantees safe handling of frames during MFCINST_FINISHING and correct clearing of workbit to avoid early stopping of encoding.
--- drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/media/platform/s5p-mfc/s5p_mfc_enc.c +10 -2
@@ -1212,6 +1212,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)unsigned long mb_y_addr, mb_c_addr;int slice_type;unsigned int strm_size; +bool src_ready; slice_type =s5p_mfc_hw_call (dev->mfc_ops, get_enc_slice_type, dev); strm_size =s5p_mfc_hw_call (dev->mfc_ops, get_enc_strm_size, dev);
@@ -1251,7 +1252,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) } } } -if ((ctx->src_queue_cnt >0 ) && (ctx->state ==MFCINST_RUNNING )) { +if (ctx->src_queue_cnt >0 && (ctx->state ==MFCINST_RUNNING || + ctx->state ==MFCINST_FINISHING )) { mb_entry = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);if (mb_entry->flags &MFC_BUF_FLAG_USED ) {
@@ -1282,7 +1284,13 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)vb2_set_plane_payload (&mb_entry->b->vb2_buf,0 , strm_size);vb2_buffer_done (&mb_entry->b->vb2_buf,VB2_BUF_STATE_DONE ); } -if ((ctx->src_queue_cnt ==0 ) || (ctx->dst_queue_cnt ==0 )) + + src_ready = true; +if (ctx->state ==MFCINST_RUNNING && ctx->src_queue_cnt ==0 ) + src_ready = false; +if (ctx->state ==MFCINST_FINISHING && ctx->ref_queue_cnt ==0 ) + src_ready = false; +if (!src_ready || ctx->dst_queue_cnt ==0 )clear_work_bit (ctx);return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 541/658 media: s5p-mfc: Clear workbit to handle error condition
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit d3f3c2fe54e30b0636496d842ffbb5ad3a547f9b ]
During error on CLOSE_INSTANCE command, ctx_work_bits was not getting cleared. During consequent mfc execution NULL pointer dereferencing of this context led to kernel panic. This patch fixes this issue by making sure to clear ctx_work_bits always.
--- drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c +3 -1
@@ -468,8 +468,10 @@ void s5p_mfc_close_mfc_inst(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx)s5p_mfc_hw_call (dev->mfc_ops, try_run, dev);/* Wait until instance is returned or timeout occurred */ if (s5p_mfc_wait_for_done_ctx (ctx, -S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET ,0 )) +S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET ,0 )){ +clear_work_bit_irqsave (ctx);mfc_err ("Err returning instance\n" ); + }/* Free resources */ s5p_mfc_hw_call (dev->mfc_ops, release_codec_buffers, ctx);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 542/658 media: s5p-mfc: Fix in register read and write for H264
In reply to Greg Kroah-HartmanFrom: Smitha T Murthy <[email protected]>
[ Upstream commit 06710cd5d2436135046898d7e4b9408c8bb99446 ]
Few of the H264 encoder registers written were not getting reflected since the read values were not stored and getting overwritten.
--- drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c +7 -7
@@ -1060,7 +1060,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx) }/* aspect ratio VUI */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<5 ); reg |= ((p_h264->vui_sar &0x1 ) <<5 );writel (reg, mfc_regs->e_h264_options);
@@ -1083,7 +1083,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)/* intra picture period for H.264 open GOP */ /* control */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<4 ); reg |= ((p_h264->open_gop &0x1 ) <<4 );writel (reg, mfc_regs->e_h264_options);
@@ -1097,23 +1097,23 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx) }/* 'WEIGHTED_BI_PREDICTION' for B is disable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x3 <<9 );writel (reg, mfc_regs->e_h264_options);/* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<14 );writel (reg, mfc_regs->e_h264_options);/* ASO */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<6 ); reg |= ((p_h264->aso &0x1 ) <<6 );writel (reg, mfc_regs->e_h264_options);/* hier qp enable */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<8 ); reg |= ((p_h264->open_gop &0x1 ) <<8 );writel (reg, mfc_regs->e_h264_options);
@@ -1134,7 +1134,7 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)writel (reg, mfc_regs->e_h264_num_t_layer);/* frame packing SEI generation */ -readl (mfc_regs->e_h264_options); + reg =readl (mfc_regs->e_h264_options); reg &= ~(0x1 <<25 ); reg |= ((p_h264->sei_frame_packing &0x1 ) <<25 );writel (reg, mfc_regs->e_h264_options);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 543/658 dm thin: resume even if in FAIL mode
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
[ Upstream commit 19eb1650afeb1aa86151f61900e9e5f1de5d8d02 ]
If a thinpool set fail_io while suspending, resume will fail with:
device-mapper: resume ioctl on vg-thinpool failed: Invalid argument
The thin-pool also can't be removed if an in-flight bio is in the deferred list.
This can be easily reproduced using:
echo "offline" > /sys/block/sda/device/state dd if=/dev/zero of=/dev/mapper/thin bs=4K count=1 dmsetup suspend /dev/mapper/pool mkfs.ext4 /dev/mapper/thin
dmsetup resume /dev/mapper/pool
The root cause is maybe_resize_data_dev() will check fail_io and return error before called dm_resume.
Fix this by adding FAIL mode check at the end of pool_preresume().
--- drivers/md/dm-thin.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/md/dm-thin.c +12 -4
@@ -3593,23 +3593,31 @@ static int pool_preresume(struct dm_target *ti)*/ r =bind_control_target (pool, ti);if (r) -return r; + goto out;dm_pool_register_pre_commit_callback (pool->pmd, metadata_pre_commit_callback, pt); r =maybe_resize_data_dev (ti, &need_commit1);if (r) -return r; + goto out; r =maybe_resize_metadata_dev (ti, &need_commit2);if (r) -return r; + goto out;if (need_commit1 || need_commit2) (void )commit (pool); +out: +/* +* When a thin-pool is PM_FAIL, it cannot be rebuilt if +* bio is in deferred list. Therefore need to return 0 +* to allow pool_resume() to flush IO. +*/ +if (r &&get_pool_mode (pool) ==PM_FAIL ) + r =0 ; -return 0 ; +return r; }static void pool_suspend_active_thins (struct pool *pool)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 544/658 perf probe: Use dwarf_attr_integrate as generic DWARF attr accessor
In reply to Greg Kroah-HartmanFrom: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit f828929ab7f0dc3353e4a617f94f297fa8f3dec3 ]
Use dwarf_attr_integrate() instead of dwarf_attr() for generic attribute acccessor functions, so that it can find the specified attribute from abstact origin DIE etc.
Stable-dep-of: a9dfc46c67b5 ("perf probe: Fix to get the DW_AT_decl_file and DW_AT_call_file as unsinged data")
--- tools/perf/util/dwarf-aux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/dwarf-aux.c +2 -2
@@ -254,7 +254,7 @@ static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name, {Dwarf_Attribute attr; -if (dwarf_attr (tp_die, attr_name, &attr) ==NULL || +if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL ||dwarf_formudata (&attr, result) !=0 )return -ENOENT ;
@@ -267,7 +267,7 @@ static int die_get_attr_sdata(Dwarf_Die *tp_die, unsigned int attr_name, {Dwarf_Attribute attr; -if (dwarf_attr (tp_die, attr_name, &attr) ==NULL || +if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL ||dwarf_formsdata (&attr, result) !=0 )return -ENOENT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 545/658 perf probe: Fix to get the DW_AT_decl_file and DW_AT_call_file as unsinged data
In reply to Greg Kroah-HartmanFrom: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit a9dfc46c67b52ad43b8e335e28f4cf8002c67793 ]
DWARF version 5 standard Sec 2.14 says that
Any debugging information entry representing the declaration of an object, module, subprogram or type may have DW_AT_decl_file, DW_AT_decl_line and DW_AT_decl_column attributes, each of whose value is an unsigned integer constant.
So it should be an unsigned integer data. Also, even though the standard doesn't clearly say the DW_AT_call_file is signed or unsigned, the elfutils (eu-readelf) interprets it as unsigned integer data and it is natural to handle it as unsigned integer data as same as DW_AT_decl_file. This changes the DW_AT_call_file as unsigned integer data too.
--- tools/perf/util/dwarf-aux.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
tools/perf/util/dwarf-aux.c +4 -17
@@ -261,19 +261,6 @@ static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name,return 0 ; } -/* Get attribute and translate it as a sdata */ -static int die_get_attr_sdata (Dwarf_Die *tp_die,unsigned int attr_name, -Dwarf_Sword *result) -{ -Dwarf_Attribute attr; - -if (dwarf_attr_integrate (tp_die, attr_name, &attr) ==NULL || -dwarf_formsdata (&attr, result) !=0 ) -return -ENOENT ; - -return 0 ; -} -/** * die_is_signed_type - Check whether a type DIE is signed or not * @tp_die: a DIE of a type
@@ -397,9 +384,9 @@ int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)/* Get the call file index number in CU DIE */ static int die_get_call_fileno (Dwarf_Die *in_die) { -Dwarf_Sword idx; +Dwarf_Word idx; -if (die_get_attr_sdata (in_die, DW_AT_call_file, &idx) ==0 ) +if (die_get_attr_udata (in_die, DW_AT_call_file, &idx) ==0 )return (int )idx;else return -ENOENT ;
@@ -408,9 +395,9 @@ static int die_get_call_fileno(Dwarf_Die *in_die)/* Get the declared file index number in CU DIE */ static int die_get_decl_fileno (Dwarf_Die *pdie) { -Dwarf_Sword idx; +Dwarf_Word idx; -if (die_get_attr_sdata (pdie, DW_AT_decl_file, &idx) ==0 ) +if (die_get_attr_udata (pdie, DW_AT_decl_file, &idx) ==0 )return (int )idx;else return -ENOENT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 546/658 KVM: x86: optimize more exit handlers in vmx.c
In reply to Greg Kroah-HartmanFrom: Andrea Arcangeli <[email protected]>
[ Upstream commit f399e60c45f6b6e6ad6dfcedff1dd6386e086b0b ]
Eliminate wasteful call/ret non RETPOLINE case and unnecessary fentry dynamic tracing hooking points.
Stable-dep-of: 31de69f4eea7 ("KVM: nVMX: Properly expose ENABLE_USR_WAIT_PAUSE control to L1")
--- arch/x86/kvm/vmx/vmx.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-)
arch/x86/kvm/vmx/vmx.c +5 -25
@@ -4802,7 +4802,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)return 0 ; } -static int handle_external_interrupt (struct kvm_vcpu *vcpu) +static __always_inline int handle_external_interrupt(struct kvm_vcpu *vcpu) { ++vcpu->stat.irq_exits;return 1 ;
@@ -5074,21 +5074,6 @@ static void vmx_set_dr7(struct kvm_vcpu *vcpu, unsigned long val)vmcs_writel (GUEST_DR7 , val); } -static int handle_cpuid (struct kvm_vcpu *vcpu) -{ -return kvm_emulate_cpuid (vcpu); -} - -static int handle_rdmsr (struct kvm_vcpu *vcpu) -{ -return kvm_emulate_rdmsr (vcpu); -} - -static int handle_wrmsr (struct kvm_vcpu *vcpu) -{ -return kvm_emulate_wrmsr (vcpu); -} -static int handle_tpr_below_threshold (struct kvm_vcpu *vcpu) {kvm_apic_update_ppr (vcpu);
@@ -5105,11 +5090,6 @@ static int handle_interrupt_window(struct kvm_vcpu *vcpu)return 1 ; } -static int handle_halt (struct kvm_vcpu *vcpu) -{ -return kvm_emulate_halt (vcpu); -} -static int handle_vmcall (struct kvm_vcpu *vcpu) {return kvm_emulate_hypercall (vcpu);
@@ -5657,11 +5637,11 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { [EXIT_REASON_IO_INSTRUCTION] = handle_io, [EXIT_REASON_CR_ACCESS] = handle_cr, [EXIT_REASON_DR_ACCESS] = handle_dr, - [EXIT_REASON_CPUID] = handle_cpuid, - [EXIT_REASON_MSR_READ] = handle_rdmsr, - [EXIT_REASON_MSR_WRITE] = handle_wrmsr, + [EXIT_REASON_CPUID] = kvm_emulate_cpuid, + [EXIT_REASON_MSR_READ] = kvm_emulate_rdmsr, + [EXIT_REASON_MSR_WRITE] = kvm_emulate_wrmsr, [EXIT_REASON_PENDING_INTERRUPT] = handle_interrupt_window, - [EXIT_REASON_HLT] = handle_halt, + [EXIT_REASON_HLT] = kvm_emulate_halt, [EXIT_REASON_INVD] = handle_invd, [EXIT_REASON_INVLPG] = handle_invlpg, [EXIT_REASON_RDPMC] = handle_rdpmc,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 547/658 KVM: retpolines: x86: eliminate retpoline from vmx.c exit handlers
In reply to Greg Kroah-HartmanFrom: Andrea Arcangeli <[email protected]>
[ Upstream commit 4289d2728664fc1fb49cfc76a6a7d96d913b921f ]
It's enough to check the exit value and issue a direct call to avoid the retpoline for all the common vmexit reasons.
Of course CONFIG_RETPOLINE already forbids gcc to use indirect jumps while compiling all switch() statements, however switch() would still allow the compiler to bisect the case value. It's more efficient to prioritize the most frequent vmexits instead.
The halt may be slow paths from the point of the guest, but not necessarily so from the point of the host if the host runs at full CPU capacity and no host CPU is ever left idle.
Stable-dep-of: 31de69f4eea7 ("KVM: nVMX: Properly expose ENABLE_USR_WAIT_PAUSE control to L1")
--- arch/x86/kvm/vmx/vmx.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/vmx.c +16 -2
@@ -6015,9 +6015,23 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu) }if (exit_reason < kvm_vmx_max_exit_handlers - && kvm_vmx_exit_handlers[exit_reason]) + && kvm_vmx_exit_handlers[exit_reason]) { +#ifdef CONFIG_RETPOLINE +if (exit_reason ==EXIT_REASON_MSR_WRITE ) +return kvm_emulate_wrmsr (vcpu); +else if (exit_reason ==EXIT_REASON_PREEMPTION_TIMER ) +return handle_preemption_timer (vcpu); +else if (exit_reason ==EXIT_REASON_PENDING_INTERRUPT ) +return handle_interrupt_window (vcpu); +else if (exit_reason ==EXIT_REASON_EXTERNAL_INTERRUPT ) +return handle_external_interrupt (vcpu); +else if (exit_reason ==EXIT_REASON_HLT ) +return kvm_emulate_halt (vcpu); +else if (exit_reason ==EXIT_REASON_EPT_MISCONFIG ) +return handle_ept_misconfig (vcpu); +#endif return kvm_vmx_exit_handlers[exit_reason](vcpu); -else { + }else {vcpu_unimpl (vcpu,"vmx: unexpected exit reason 0x%x\n" , exit_reason);dump_vmcs ();
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 548/658 KVM: VMX: Rename INTERRUPT_PENDING to INTERRUPT_WINDOW
In reply to Greg Kroah-HartmanFrom: Xiaoyao Li <[email protected]>
[ Upstream commit 9dadc2f918df26e64aa04794cdb4d8667c934f47 ]
Rename interrupt-windown exiting related definitions to match the latest Intel SDM. No functional changes.
Stable-dep-of: 31de69f4eea7 ("KVM: nVMX: Properly expose ENABLE_USR_WAIT_PAUSE control to L1")
--- arch/x86/include/asm/vmx.h | 2 +- arch/x86/include/uapi/asm/vmx.h | 4 ++-- arch/x86/kvm/vmx/nested.c | 12 ++++++------ arch/x86/kvm/vmx/vmx.c | 10 +++++----- tools/arch/x86/include/uapi/asm/vmx.h | 4 ++-- tools/testing/selftests/kvm/include/x86_64/vmx.h | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-)
arch/x86/include/asm/vmx.h +1 -1
@@ -19,7 +19,7 @@/* * Definitions of Primary Processor-Based VM-Execution Controls. */ -#define CPU_BASED_VIRTUAL_INTR_PENDING 0x00000004 +#define CPU_BASED_INTR_WINDOW_EXITING 0x00000004#define CPU_BASED_USE_TSC_OFFSETING 0x00000008#define CPU_BASED_HLT_EXITING 0x00000080#define CPU_BASED_INVLPG_EXITING 0x00000200
arch/x86/include/uapi/asm/vmx.h +2 -2
@@ -33,7 +33,7 @@#define EXIT_REASON_TRIPLE_FAULT 2#define EXIT_REASON_INIT_SIGNAL 3 -#define EXIT_REASON_PENDING_INTERRUPT 7 +#define EXIT_REASON_INTERRUPT_WINDOW 7#define EXIT_REASON_NMI_WINDOW 8#define EXIT_REASON_TASK_SWITCH 9#define EXIT_REASON_CPUID 10
@@ -94,7 +94,7 @@ { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" }, \ { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" }, \ { EXIT_REASON_INIT_SIGNAL, "INIT_SIGNAL" }, \ - { EXIT_REASON_PENDING_INTERRUPT, "PENDING_INTERRUPT" }, \ + { EXIT_REASON_INTERRUPT_WINDOW, "INTERRUPT_WINDOW" }, \ { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" }, \ { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" }, \ { EXIT_REASON_CPUID, "CPUID" }, \
arch/x86/kvm/vmx/nested.c +6 -6
@@ -2073,7 +2073,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)* EXEC CONTROLS */ exec_control =vmx_exec_control (vmx);/* L0's desires */ - exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING ; + exec_control &= ~CPU_BASED_INTR_WINDOW_EXITING ; exec_control &= ~CPU_BASED_VIRTUAL_NMI_PENDING ; exec_control &= ~CPU_BASED_TPR_SHADOW ; exec_control |= vmcs12->cpu_based_vm_exec_control;
@@ -3039,7 +3039,7 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,u32 exit_qual; evaluate_pending_interrupts =exec_controls_get (vmx) & - (CPU_BASED_VIRTUAL_INTR_PENDING |CPU_BASED_VIRTUAL_NMI_PENDING ); + (CPU_BASED_INTR_WINDOW_EXITING |CPU_BASED_VIRTUAL_NMI_PENDING );if (likely (!evaluate_pending_interrupts) &&kvm_vcpu_apicv_active (vcpu)) evaluate_pending_interrupts |=vmx_has_apicv_interrupt (vcpu);
@@ -3268,7 +3268,7 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)if ((vmcs12->guest_activity_state ==GUEST_ACTIVITY_HLT ) && !(vmcs12->vm_entry_intr_info_field &INTR_INFO_VALID_MASK ) && !(vmcs12->cpu_based_vm_exec_control &CPU_BASED_VIRTUAL_NMI_PENDING ) && - !((vmcs12->cpu_based_vm_exec_control &CPU_BASED_VIRTUAL_INTR_PENDING ) && + !((vmcs12->cpu_based_vm_exec_control &CPU_BASED_INTR_WINDOW_EXITING ) && (vmcs12->guest_rflags &X86_EFLAGS_IF ))) { vmx->nested.nested_run_pending =0 ;return kvm_vcpu_halt (vcpu);
@@ -5376,8 +5376,8 @@ bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)return false;case EXIT_REASON_TRIPLE_FAULT :return true; -case EXIT_REASON_PENDING_INTERRUPT : -return nested_cpu_has (vmcs12,CPU_BASED_VIRTUAL_INTR_PENDING ); +case EXIT_REASON_INTERRUPT_WINDOW : +return nested_cpu_has (vmcs12,CPU_BASED_INTR_WINDOW_EXITING );case EXIT_REASON_NMI_WINDOW :return nested_cpu_has (vmcs12,CPU_BASED_VIRTUAL_NMI_PENDING );case EXIT_REASON_TASK_SWITCH :
@@ -5869,7 +5869,7 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) msrs->procbased_ctls_low =CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR ; msrs->procbased_ctls_high &= -CPU_BASED_VIRTUAL_INTR_PENDING | +CPU_BASED_INTR_WINDOW_EXITING |CPU_BASED_VIRTUAL_NMI_PENDING |CPU_BASED_USE_TSC_OFFSETING |CPU_BASED_HLT_EXITING |CPU_BASED_INVLPG_EXITING | CPU_BASED_MWAIT_EXITING | CPU_BASED_CR3_LOAD_EXITING |
arch/x86/kvm/vmx/vmx.c +5 -5
@@ -4458,7 +4458,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)static void enable_irq_window (struct kvm_vcpu *vcpu) { -exec_controls_setbit (to_vmx (vcpu),CPU_BASED_VIRTUAL_INTR_PENDING ); +exec_controls_setbit (to_vmx (vcpu),CPU_BASED_INTR_WINDOW_EXITING ); }static void enable_nmi_window (struct kvm_vcpu *vcpu)
@@ -5082,7 +5082,7 @@ static int handle_tpr_below_threshold(struct kvm_vcpu *vcpu)static int handle_interrupt_window (struct kvm_vcpu *vcpu) { -exec_controls_clearbit (to_vmx (vcpu),CPU_BASED_VIRTUAL_INTR_PENDING ); +exec_controls_clearbit (to_vmx (vcpu),CPU_BASED_INTR_WINDOW_EXITING );kvm_make_request (KVM_REQ_EVENT , vcpu);
@@ -5316,7 +5316,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)WARN_ON_ONCE (vmx->emulation_required && vmx->nested.nested_run_pending); intr_window_requested =exec_controls_get (vmx) & -CPU_BASED_VIRTUAL_INTR_PENDING ; +CPU_BASED_INTR_WINDOW_EXITING ;while (vmx->emulation_required && count-- !=0 ) {if (intr_window_requested &&vmx_interrupt_allowed (vcpu))
@@ -5640,7 +5640,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { [EXIT_REASON_CPUID] = kvm_emulate_cpuid, [EXIT_REASON_MSR_READ] = kvm_emulate_rdmsr, [EXIT_REASON_MSR_WRITE] = kvm_emulate_wrmsr, - [EXIT_REASON_PENDING_INTERRUPT] = handle_interrupt_window, + [EXIT_REASON_INTERRUPT_WINDOW] = handle_interrupt_window, [EXIT_REASON_HLT] = kvm_emulate_halt, [EXIT_REASON_INVD] = handle_invd, [EXIT_REASON_INVLPG] = handle_invlpg,
@@ -6021,7 +6021,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)return kvm_emulate_wrmsr (vcpu); else if (exit_reason == EXIT_REASON_PREEMPTION_TIMER) return handle_preemption_timer(vcpu); - else if (exit_reason == EXIT_REASON_PENDING_INTERRUPT) + else if (exit_reason == EXIT_REASON_INTERRUPT_WINDOW) return handle_interrupt_window(vcpu); else if (exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT) return handle_external_interrupt(vcpu);
tools/arch/x86/include/uapi/asm/vmx.h +2 -2
@@ -33,7 +33,7 @@#define EXIT_REASON_TRIPLE_FAULT 2#define EXIT_REASON_INIT_SIGNAL 3 -#define EXIT_REASON_PENDING_INTERRUPT 7 +#define EXIT_REASON_INTERRUPT_WINDOW 7#define EXIT_REASON_NMI_WINDOW 8#define EXIT_REASON_TASK_SWITCH 9#define EXIT_REASON_CPUID 10
@@ -94,7 +94,7 @@ { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" }, \ { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" }, \ { EXIT_REASON_INIT_SIGNAL, "INIT_SIGNAL" }, \ - { EXIT_REASON_PENDING_INTERRUPT, "PENDING_INTERRUPT" }, \ + { EXIT_REASON_INTERRUPT_WINDOW, "INTERRUPT_WINDOW" }, \ { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" }, \ { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" }, \ { EXIT_REASON_CPUID, "CPUID" }, \
tools/testing/selftests/kvm/include/x86_64/vmx.h +2 -2
@@ -18,7 +18,7 @@/* * Definitions of Primary Processor-Based VM-Execution Controls. */ -#define CPU_BASED_VIRTUAL_INTR_PENDING 0x00000004 +#define CPU_BASED_INTR_WINDOW_EXITING 0x00000004#define CPU_BASED_USE_TSC_OFFSETING 0x00000008#define CPU_BASED_HLT_EXITING 0x00000080#define CPU_BASED_INVLPG_EXITING 0x00000200
@@ -103,7 +103,7 @@#define EXIT_REASON_EXCEPTION_NMI 0#define EXIT_REASON_EXTERNAL_INTERRUPT 1#define EXIT_REASON_TRIPLE_FAULT 2 -#define EXIT_REASON_PENDING_INTERRUPT 7 +#define EXIT_REASON_INTERRUPT_WINDOW 7#define EXIT_REASON_NMI_WINDOW 8#define EXIT_REASON_TASK_SWITCH 9#define EXIT_REASON_CPUID 10
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 549/658 KVM: VMX: Rename NMI_PENDING to NMI_WINDOW
In reply to Greg Kroah-HartmanFrom: Xiaoyao Li <[email protected]>
[ Upstream commit 4e2a0bc56ad197e5ccfab8395649b681067fe8cb ]
Rename the NMI-window exiting related definitions to match the latest Intel SDM. No functional changes.
Stable-dep-of: 31de69f4eea7 ("KVM: nVMX: Properly expose ENABLE_USR_WAIT_PAUSE control to L1")
--- arch/x86/include/asm/vmx.h | 2 +- arch/x86/kvm/vmx/nested.c | 12 ++++++------ arch/x86/kvm/vmx/vmx.c | 4 ++-- tools/testing/selftests/kvm/include/x86_64/vmx.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/include/asm/vmx.h +1 -1
@@ -31,7 +31,7 @@#define CPU_BASED_CR8_LOAD_EXITING 0x00080000#define CPU_BASED_CR8_STORE_EXITING 0x00100000#define CPU_BASED_TPR_SHADOW 0x00200000 -#define CPU_BASED_VIRTUAL_NMI_PENDING 0x00400000 +#define CPU_BASED_NMI_WINDOW_EXITING 0x00400000#define CPU_BASED_MOV_DR_EXITING 0x00800000#define CPU_BASED_UNCOND_IO_EXITING 0x01000000#define CPU_BASED_USE_IO_BITMAPS 0x02000000
arch/x86/kvm/vmx/nested.c +6 -6
@@ -2074,7 +2074,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)*/ exec_control =vmx_exec_control (vmx);/* L0's desires */ exec_control &= ~CPU_BASED_INTR_WINDOW_EXITING ; - exec_control &= ~CPU_BASED_VIRTUAL_NMI_PENDING ; + exec_control &= ~CPU_BASED_NMI_WINDOW_EXITING ; exec_control &= ~CPU_BASED_TPR_SHADOW ; exec_control |= vmcs12->cpu_based_vm_exec_control;
@@ -2459,7 +2459,7 @@ static int nested_vmx_check_nmi_controls(struct vmcs12 *vmcs12)return -EINVAL ;if (CC (!nested_cpu_has_virtual_nmis (vmcs12) && -nested_cpu_has (vmcs12,CPU_BASED_VIRTUAL_NMI_PENDING ))) +nested_cpu_has (vmcs12,CPU_BASED_NMI_WINDOW_EXITING )))return -EINVAL ;return 0 ;
@@ -3039,7 +3039,7 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,u32 exit_qual; evaluate_pending_interrupts =exec_controls_get (vmx) & - (CPU_BASED_INTR_WINDOW_EXITING |CPU_BASED_VIRTUAL_NMI_PENDING ); + (CPU_BASED_INTR_WINDOW_EXITING |CPU_BASED_NMI_WINDOW_EXITING );if (likely (!evaluate_pending_interrupts) &&kvm_vcpu_apicv_active (vcpu)) evaluate_pending_interrupts |=vmx_has_apicv_interrupt (vcpu);
@@ -3267,7 +3267,7 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)*/ if ((vmcs12->guest_activity_state ==GUEST_ACTIVITY_HLT ) && !(vmcs12->vm_entry_intr_info_field &INTR_INFO_VALID_MASK ) && - !(vmcs12->cpu_based_vm_exec_control &CPU_BASED_VIRTUAL_NMI_PENDING ) && + !(vmcs12->cpu_based_vm_exec_control &CPU_BASED_NMI_WINDOW_EXITING ) && !((vmcs12->cpu_based_vm_exec_control &CPU_BASED_INTR_WINDOW_EXITING ) && (vmcs12->guest_rflags &X86_EFLAGS_IF ))) { vmx->nested.nested_run_pending =0 ;
@@ -5379,7 +5379,7 @@ bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)case EXIT_REASON_INTERRUPT_WINDOW :return nested_cpu_has (vmcs12,CPU_BASED_INTR_WINDOW_EXITING );case EXIT_REASON_NMI_WINDOW : -return nested_cpu_has (vmcs12,CPU_BASED_VIRTUAL_NMI_PENDING ); +return nested_cpu_has (vmcs12,CPU_BASED_NMI_WINDOW_EXITING );case EXIT_REASON_TASK_SWITCH :return true;case EXIT_REASON_CPUID :
@@ -5870,7 +5870,7 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR ; msrs->procbased_ctls_high &=CPU_BASED_INTR_WINDOW_EXITING | -CPU_BASED_VIRTUAL_NMI_PENDING |CPU_BASED_USE_TSC_OFFSETING | +CPU_BASED_NMI_WINDOW_EXITING |CPU_BASED_USE_TSC_OFFSETING |CPU_BASED_HLT_EXITING |CPU_BASED_INVLPG_EXITING |CPU_BASED_MWAIT_EXITING |CPU_BASED_CR3_LOAD_EXITING | CPU_BASED_CR3_STORE_EXITING |
arch/x86/kvm/vmx/vmx.c +2 -2
@@ -4469,7 +4469,7 @@ static void enable_nmi_window(struct kvm_vcpu *vcpu)return ; } -exec_controls_setbit (to_vmx (vcpu),CPU_BASED_VIRTUAL_NMI_PENDING ); +exec_controls_setbit (to_vmx (vcpu),CPU_BASED_NMI_WINDOW_EXITING ); }static void vmx_inject_irq (struct kvm_vcpu *vcpu)
@@ -5295,7 +5295,7 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)static int handle_nmi_window (struct kvm_vcpu *vcpu) {WARN_ON_ONCE (!enable_vnmi); -exec_controls_clearbit (to_vmx (vcpu),CPU_BASED_VIRTUAL_NMI_PENDING ); +exec_controls_clearbit (to_vmx (vcpu),CPU_BASED_NMI_WINDOW_EXITING ); ++vcpu->stat.nmi_window_exits;kvm_make_request (KVM_REQ_EVENT , vcpu);
tools/testing/selftests/kvm/include/x86_64/vmx.h +1 -1
@@ -30,7 +30,7 @@#define CPU_BASED_CR8_LOAD_EXITING 0x00080000#define CPU_BASED_CR8_STORE_EXITING 0x00100000#define CPU_BASED_TPR_SHADOW 0x00200000 -#define CPU_BASED_VIRTUAL_NMI_PENDING 0x00400000 +#define CPU_BASED_NMI_WINDOW_EXITING 0x00400000#define CPU_BASED_MOV_DR_EXITING 0x00800000#define CPU_BASED_UNCOND_IO_EXITING 0x01000000#define CPU_BASED_USE_IO_BITMAPS 0x02000000
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 550/658 KVM: VMX: Fix the spelling of CPU_BASED_USE_TSC_OFFSETTING
In reply to Greg Kroah-HartmanFrom: Xiaoyao Li <[email protected]>
[ Upstream commit 5e3d394fdd9e6b49cd8b28d85adff100a5bddc66 ]
The mis-spelling is found by checkpatch.pl, so fix them.
Stable-dep-of: 31de69f4eea7 ("KVM: nVMX: Properly expose ENABLE_USR_WAIT_PAUSE control to L1")
--- arch/x86/include/asm/vmx.h | 2 +- arch/x86/kvm/vmx/nested.c | 8 ++++---- arch/x86/kvm/vmx/vmx.c | 6 +++--- tools/testing/selftests/kvm/include/x86_64/vmx.h | 2 +- tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/include/asm/vmx.h +1 -1
@@ -20,7 +20,7 @@* Definitions of Primary Processor-Based VM-Execution Controls. */ #define CPU_BASED_INTR_WINDOW_EXITING 0x00000004 -#define CPU_BASED_USE_TSC_OFFSETING 0x00000008 +#define CPU_BASED_USE_TSC_OFFSETTING 0x00000008#define CPU_BASED_HLT_EXITING 0x00000080#define CPU_BASED_INVLPG_EXITING 0x00000200#define CPU_BASED_MWAIT_EXITING 0x00000400
arch/x86/kvm/vmx/nested.c +4 -4
@@ -3090,7 +3090,7 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, }enter_guest_mode (vcpu); -if (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETING ) +if (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETTING ) vcpu->arch.tsc_offset += vmcs12->tsc_offset;if (prepare_vmcs02 (vcpu, vmcs12, &exit_qual))
@@ -3154,7 +3154,7 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,* 26.7 "VM-entry failures during or after loading guest state". */ vmentry_fail_vmexit_guest_mode: -if (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETING ) +if (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETTING ) vcpu->arch.tsc_offset -= vmcs12->tsc_offset;leave_guest_mode (vcpu);
@@ -4073,7 +4073,7 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,if (nested_cpu_has_preemption_timer (vmcs12))hrtimer_cancel (&to_vmx (vcpu)->nested.preemption_timer); -if (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETING ) +if (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETTING ) vcpu->arch.tsc_offset -= vmcs12->tsc_offset;if (likely (!vmx->fail)) {
@@ -5870,7 +5870,7 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR ; msrs->procbased_ctls_high &=CPU_BASED_INTR_WINDOW_EXITING | -CPU_BASED_NMI_WINDOW_EXITING |CPU_BASED_USE_TSC_OFFSETING | +CPU_BASED_NMI_WINDOW_EXITING |CPU_BASED_USE_TSC_OFFSETTING |CPU_BASED_HLT_EXITING |CPU_BASED_INVLPG_EXITING |CPU_BASED_MWAIT_EXITING |CPU_BASED_CR3_LOAD_EXITING | CPU_BASED_CR3_STORE_EXITING |
arch/x86/kvm/vmx/vmx.c +3 -3
@@ -1780,7 +1780,7 @@ static u64 vmx_read_l1_tsc_offset(struct kvm_vcpu *vcpu)struct vmcs12 *vmcs12 =get_vmcs12 (vcpu);if (is_guest_mode (vcpu) && - (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETING )) + (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETTING ))return vcpu->arch.tsc_offset - vmcs12->tsc_offset;return vcpu->arch.tsc_offset;
@@ -1798,7 +1798,7 @@ static u64 vmx_write_l1_tsc_offset(struct kvm_vcpu *vcpu, u64 offset)* to the newly set TSC to get L2's TSC. */ if (is_guest_mode (vcpu) && - (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETING )) + (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETTING )) g_tsc_offset = vmcs12->tsc_offset; trace_kvm_write_tsc_offset(vcpu->vcpu_id,
@@ -2425,7 +2425,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,CPU_BASED_CR3_STORE_EXITING |CPU_BASED_UNCOND_IO_EXITING |CPU_BASED_MOV_DR_EXITING | -CPU_BASED_USE_TSC_OFFSETING | +CPU_BASED_USE_TSC_OFFSETTING |CPU_BASED_MWAIT_EXITING |CPU_BASED_MONITOR_EXITING | CPU_BASED_INVLPG_EXITING |
tools/testing/selftests/kvm/include/x86_64/vmx.h +1 -1
@@ -19,7 +19,7 @@* Definitions of Primary Processor-Based VM-Execution Controls. */ #define CPU_BASED_INTR_WINDOW_EXITING 0x00000004 -#define CPU_BASED_USE_TSC_OFFSETING 0x00000008 +#define CPU_BASED_USE_TSC_OFFSETTING 0x00000008#define CPU_BASED_HLT_EXITING 0x00000080#define CPU_BASED_INVLPG_EXITING 0x00000200#define CPU_BASED_MWAIT_EXITING 0x00000400
tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c +1 -1
@@ -98,7 +98,7 @@ static void l1_guest_code(struct vmx_pages *vmx_pages)prepare_vmcs (vmx_pages, l2_guest_code, &l2_guest_stack[L2_GUEST_STACK_SIZE ]); control =vmreadz (CPU_BASED_VM_EXEC_CONTROL ); - control |=CPU_BASED_USE_MSR_BITMAPS |CPU_BASED_USE_TSC_OFFSETING ; + control |=CPU_BASED_USE_MSR_BITMAPS |CPU_BASED_USE_TSC_OFFSETTING ;vmwrite (CPU_BASED_VM_EXEC_CONTROL , control);vmwrite (TSC_OFFSET ,TSC_OFFSET_VALUE );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 551/658 KVM: nVMX: Properly expose ENABLE_USR_WAIT_PAUSE control to L1
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
[ Upstream commit 31de69f4eea77b28a9724b3fa55aae104fc91fc7 ]
Set ENABLE_USR_WAIT_PAUSE in KVM's supported VMX MSR configuration if the feature is supported in hardware and enabled in KVM's base, non-nested configuration, i.e. expose ENABLE_USR_WAIT_PAUSE to L1 if it's supported. This fixes a bug where saving/restoring, i.e. migrating, a vCPU will fail if WAITPKG (the associated CPUID feature) is enabled for the vCPU, and obviously allows L1 to enable the feature for L2.
KVM already effectively exposes ENABLE_USR_WAIT_PAUSE to L1 by stuffing the allowed-1 control ina vCPU's virtual MSR_IA32_VMX_PROCBASED_CTLS2 when updating secondary controls in response to KVM_SET_CPUID(2), but (a) that depends on flawed code (KVM shouldn't touch VMX MSRs in response to CPUID updates) and (b) runs afoul of vmx_restore_control_msr()'s restriction that the guest value must be a strict subset of the supported host value.
Although no past commit explicitly enabled nested support for WAITPKG, doing so is safe and functionally correct from an architectural perspective as no additional KVM support is needed to virtualize TPAUSE, UMONITOR, and UMWAIT for L2 relative to L1, and KVM already forwards VM-Exits to L1 as necessary (commit bf653b78f960, "KVM: vmx: Introduce handle_unexpected_vmexit and handle WAITPKG vmexit").
Note, KVM always keeps the hosts MSR_IA32_UMWAIT_CONTROL resident in hardware, i.e. always runs both L1 and L2 with the host's power management settings for TPAUSE and UMWAIT. See commit bf09fb6cba4f ("KVM: VMX: Stop context switching MSR_IA32_UMWAIT_CONTROL") for more details.
Message-Id: <[email protected]>
--- arch/x86/kvm/vmx/nested.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/nested.c +2 -1
@@ -5916,7 +5916,8 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)SECONDARY_EXEC_RDRAND_EXITING |SECONDARY_EXEC_ENABLE_INVPCID |SECONDARY_EXEC_RDSEED_EXITING | -SECONDARY_EXEC_XSAVES ; +SECONDARY_EXEC_XSAVES | +SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE ;/* * We can emulate "VMCS shadowing," even if the hardware
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 552/658 ravb: Fix "failed to switch device to config mode" message during unbind
In reply to Greg Kroah-HartmanFrom: Biju Das <[email protected]>
[ Upstream commit c72a7e42592b2e18d862cf120876070947000d7a ]
This patch fixes the error "ravb 11c20000.ethernet eth0: failed to switch device to config mode" during unbind.
We are doing register access after pm_runtime_put_sync().
We usually do cleanup in reverse order of init. Currently in remove(), the "pm_runtime_put_sync" is not in reverse order.
Probe
reset_control_deassert(rstc); pm_runtime_enable(&pdev->dev); pm_runtime_get_sync(&pdev->dev);
remove
pm_runtime_put_sync(&pdev->dev); unregister_netdev(ndev); .. ravb_mdio_release(priv); pm_runtime_disable(&pdev->dev);
Consider the call to unregister_netdev() unregister_netdev->unregister_netdevice_queue->rollback_registered_many that calls the below functions which access the registers after pm_runtime_put_sync()
1) ravb_get_stats
2) ravb_close
--- drivers/net/ethernet/renesas/ravb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/renesas/ravb_main.c +1 -1
@@ -2216,11 +2216,11 @@ static int ravb_remove(struct platform_device *pdev) priv->desc_bat_dma);/* Set reset mode */ ravb_write (ndev,CCC_OPC_RESET ,CCC ); -pm_runtime_put_sync (&pdev->dev);unregister_netdev (ndev);netif_napi_del (&priv->napi[RAVB_NC ]);netif_napi_del (&priv->napi[RAVB_BE ]);ravb_mdio_release (priv); +pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);free_netdev (ndev);platform_set_drvdata (pdev,NULL );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 553/658 riscv/stacktrace: Fix stack output without ra on the stack top
In reply to Greg Kroah-HartmanFrom: Chen Huang <[email protected]>
[ Upstream commit f766f77a74f5784d8d4d3c36b1900731f97d08d0 ]
When a function doesn't have a callee, then it will not push ra into the stack, such as lkdtm_BUG() function,
addi sp,sp,-16
sd s0,8(sp)
addi s0,sp,16
ebreak
The struct stackframe use {fp,ra} to get information from stack, if walk_stackframe() with pr_regs, we will obtain wrong value and bad stacktrace,
[<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8 ---[ end trace 18da3fbdf08e25d5 ]---
Correct the next fp and pc, after that, full stacktrace shown as expects,
[<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8 [<ffffffe0008b24a4>] lkdtm_do_action+0x14/0x1c [<ffffffe00066c372>] direct_entry+0xc0/0x10a [<ffffffe000439f86>] full_proxy_write+0x42/0x6a [<ffffffe000309626>] vfs_write+0x7e/0x214 [<ffffffe00030992a>] ksys_write+0x98/0xc0 [<ffffffe000309960>] sys_write+0xe/0x16 [<ffffffe0002014bc>] ret_from_syscall+0x0/0x2 ---[ end trace 61917f3d9a9fadcd ]---
Stable-dep-of: 5c3022e4a616 ("riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument")
--- arch/riscv/kernel/stacktrace.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/riscv/kernel/stacktrace.c +9 -3
@@ -55,9 +55,15 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,/* Unwind stack frame */ frame = (struct stackframe *)fp -1 ; sp = fp; - fp = frame->fp; - pc =ftrace_graph_ret_addr (current,NULL , frame->ra, - (unsigned long *)(fp -8 )); +if (regs && (regs->epc == pc) && (frame->fp &0x7 )) { + fp = frame->ra; + pc = regs->ra; + }else { + fp = frame->fp; + pc =ftrace_graph_ret_addr (current,NULL , frame->ra, + (unsigned long *)(fp -8 )); + } + } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 554/658 riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument
In reply to Greg Kroah-HartmanFrom: Guo Ren <[email protected]>
[ Upstream commit 5c3022e4a616d800cf5f4c3a981d7992179e44a1 ]
The 'retp' is a pointer to the return address on the stack, so we must pass the current return address pointer as the 'retp' argument to ftrace_push_return_trace(). Not parent function's return address on the stack.
--- arch/riscv/kernel/stacktrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/stacktrace.c +1 -1
@@ -61,7 +61,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, }else { fp = frame->fp; pc =ftrace_graph_ret_addr (current,NULL , frame->ra, - (unsigned long *)(fp -8 )); + &frame->ra); } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 555/658 ext4: goto right label failed_mount3a
In reply to Greg Kroah-HartmanFrom: Jason Yan <[email protected]>
[ Upstream commit 43bd6f1b49b61f43de4d4e33661b8dbe8c911f14 ]
Before these two branches neither loaded the journal nor created the xattr cache. So the right label to goto is 'failed_mount3a'. Although this did not cause any issues because the error handler validated if the pointer is null. However this still made me confused when reading the code. So it's still worth to modify to goto the right label.
Stable-dep-of: 89481b5fa8c0 ("ext4: correct inconsistent error msg in nojournal mode")
--- fs/ext4/super.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/ext4/super.c +5 -5
@@ -4388,30 +4388,30 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ext4_has_feature_journal_needs_recovery(sb)) { ext4_msg(sb, KERN_ERR, "required journal recovery " "suppressed and not mounted read-only"); - goto failed_mount_wq; + goto failed_mount3a; } else {/* Nojournal mode, all journal mount options are illegal */ if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) {ext4_msg (sb,KERN_ERR ,"can't mount with " "journal_checksum, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; }if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) {ext4_msg (sb,KERN_ERR ,"can't mount with " "journal_async_commit, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; }if (sbi->s_commit_interval !=JBD2_DEFAULT_MAX_COMMIT_AGE *HZ ) {ext4_msg (sb,KERN_ERR ,"can't mount with " "commit=%lu, fs mounted w/o journal" , sbi->s_commit_interval /HZ ); - goto failed_mount_wq; + goto failed_mount3a; }if (EXT4_MOUNT_DATA_FLAGS & (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {ext4_msg (sb,KERN_ERR ,"can't mount with " "data=, fs mounted w/o journal" ); - goto failed_mount_wq; + goto failed_mount3a; } sbi->s_def_mount_opt &= ~EXT4_MOUNT_JOURNAL_CHECKSUM ;clear_opt (sb,JOURNAL_CHECKSUM );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 556/658 ext4: correct inconsistent error msg in nojournal mode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
[ Upstream commit 89481b5fa8c0640e62ba84c6020cee895f7ac643 ]
When we used the journal_async_commit mounting option in nojournal mode, the kernel told me that "can't mount with journal_checksum", was very confusing. I find that when we mount with journal_async_commit, both the JOURNAL_ASYNC_COMMIT and EXPLICIT_JOURNAL_CHECKSUM flags are set. However, in the error branch, CHECKSUM is checked before ASYNC_COMMIT. As a result, the above inconsistency occurs, and the ASYNC_COMMIT branch becomes dead code that cannot be executed. Therefore, we exchange the positions of the two judgments to make the error msg more accurate.
--- fs/ext4/super.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/ext4/super.c +5 -4
@@ -4391,14 +4391,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount3a; }else {/* Nojournal mode, all journal mount options are illegal */ -if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) { +if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) {ext4_msg (sb,KERN_ERR ,"can't mount with " -"journal_checksum, fs mounted w/o journal" ); +"journal_async_commit, fs mounted w/o journal" ); goto failed_mount3a; } -if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) { + +if (test_opt2 (sb,EXPLICIT_JOURNAL_CHECKSUM )) {ext4_msg (sb,KERN_ERR ,"can't mount with " -"journal_async_commit, fs mounted w/o journal" ); +"journal_checksum, fs mounted w/o journal" ); goto failed_mount3a; }if (sbi->s_commit_interval !=JBD2_DEFAULT_MAX_COMMIT_AGE *HZ ) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 557/658 mm/highmem: Lift memcpy_[to|from]_page to core
In reply to Greg Kroah-HartmanFrom: Ira Weiny <[email protected]>
[ Upstream commit bb90d4bc7b6a536b2e4db45f4763e467c2008251 ]
Working through a conversion to a call kmap_local_page() instead of kmap() revealed many places where the pattern kmap/memcpy/kunmap occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al Viro all suggested putting this code into helper functions. Al Viro further pointed out that these functions already existed in the iov_iter code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the functionality well. pagemap.h made some sense but is for page cache functionality.[2]
Another alternative would be to create a new header for the promoted memcpy functions, but it masks the fact that these are designed to copy to/from pages using the kernel direct mappings and complicates matters with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the changes being proposed in the functionality of kmap. From a caller perspective including/using 'highmem.h' implies that the functions defined in that header are only required when highmem is in use which is increasingly not the case with modern processors. However, highmem.h is where all the current functions like this reside (zero_user(), clear_highpage(), clear_user_highpage(), copy_user_highpage(), and copy_highpage()). So it makes the most sense even though it is distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/#t
https://lore.kernel.org/lkml/[email protected]/
Stable-dep-of: 956510c0c743 ("fs: ext4: initialize fsdata in pagecache_write()")
--- include/linux/highmem.h | 18 ++++++++++++++++++ lib/iov_iter.c | 14 -------------- 2 files changed, 18 insertions(+), 14 deletions(-)
include/linux/highmem.h +18 -0
@@ -276,4 +276,22 @@ static inline void copy_highpage(struct page *to, struct page *from)#endif +static inline void memcpy_from_page (char *to,struct page *page, +size_t offset,size_t len) +{ +char *from =kmap_atomic (page); + +memcpy (to, from + offset, len); +kunmap_atomic (from); +} + +static inline void memcpy_to_page (struct page *page,size_t offset, +const char *from,size_t len) +{ +char *to =kmap_atomic (page); + +memcpy (to + offset, from, len); +kunmap_atomic (to); +} +#endif /* _LINUX_HIGHMEM_H */
lib/iov_iter.c +0 -14
@@ -455,20 +455,6 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction, }EXPORT_SYMBOL (iov_iter_init); -static void memcpy_from_page (char *to,struct page *page,size_t offset,size_t len) -{ -char *from =kmap_atomic (page); -memcpy (to, from + offset, len); -kunmap_atomic (from); -} - -static void memcpy_to_page (struct page *page,size_t offset,const char *from,size_t len) -{ -char *to =kmap_atomic (page); -memcpy (to + offset, from, len); -kunmap_atomic (to); -} -static void memzero_page (struct page *page,size_t offset,size_t len) {char *addr =kmap_atomic (page);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 558/658 ext4: use memcpy_to_page() in pagecache_write()
In reply to Greg Kroah-HartmanFrom: Chaitanya Kulkarni <[email protected]>
[ Upstream commit bd256fda92efe97b692dc72e246d35fa724d42d8 ]
Stable-dep-of: 956510c0c743 ("fs: ext4: initialize fsdata in pagecache_write()")
--- fs/ext4/verity.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/ext4/verity.c +1 -4
@@ -80,7 +80,6 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count, PAGE_SIZE - offset_in_page(pos));struct page *page;void *fsdata; -void *addr;int res; res = pagecache_write_begin(NULL, inode->i_mapping, pos, n, 0,
@@ -88,9 +87,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,if (res)return res; - addr =kmap_atomic (page); -memcpy (addr +offset_in_page (pos), buf, n); -kunmap_atomic (addr); +memcpy_to_page (page,offset_in_page (pos), buf, n); res =pagecache_write_end (NULL , inode->i_mapping, pos, n, n, page, fsdata);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 559/658 fs: ext4: initialize fsdata in pagecache_write()
In reply to Greg Kroah-HartmanFrom: Alexander Potapenko <[email protected]>
[ Upstream commit 956510c0c7439e90b8103aaeaf4da92878c622f0 ]
When aops->write_begin() does not initialize fsdata, KMSAN reports an error passing the latter to aops->write_end().
Fix this by unconditionally initializing fsdata.
--- fs/ext4/verity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/verity.c +1 -1
@@ -79,7 +79,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,size_t n =min_t (size_t, count,PAGE_SIZE -offset_in_page (pos));struct page *page; -void *fsdata; +void *fsdata =NULL ;int res; res = pagecache_write_begin(NULL, inode->i_mapping, pos, n, 0,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 560/658 ext4: use kmemdup() to replace kmalloc + memcpy
In reply to Greg Kroah-HartmanFrom: Shuqi Zhang <[email protected]>
[ Upstream commit 4efd9f0d120c55b08852ee5605dbb02a77089a5d ]
Replace kmalloc + memcpy with kmemdup()
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/xattr.c +1 -2
@@ -1907,11 +1907,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,unlock_buffer (bs->bh);ea_bdebug (bs->bh,"cloning" ); - s->base =kmalloc (bs->bh->b_size,GFP_NOFS ); + s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); error = -ENOMEM ;if (s->base ==NULL ) goto cleanup; -memcpy (s->base,BHDR (bs->bh), bs->bh->b_size); s->first =ENTRY (header (s->base)+1 );header (s->base)->h_refcount =cpu_to_le32 (1 ); s->here =ENTRY (s->base + offset);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 561/658 mbcache: dont reclaim used entries
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 58318914186c157477b978b1739dfe2f1b9dc0fe ]
Do not reclaim entries that are currently used by somebody from a shrinker. Firstly, these entries are likely useful. Secondly, we will need to keep such entries to protect pending increment of xattr block refcount.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/mbcache.c +9 -1
@@ -288,7 +288,7 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache,while (nr_to_scan-- && !list_empty (&cache->c_list)) { entry =list_first_entry (&cache->c_list, struct mb_cache_entry, e_list); -if (entry->e_referenced) { +if (entry->e_referenced ||atomic_read (&entry->e_refcnt) >2 ) { entry->e_referenced =0 ;list_move_tail (&entry->e_list, &cache->c_list);continue ;
@@ -302,6 +302,14 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache,spin_unlock (&cache->c_list_lock); head =mb_cache_entry_head (cache, entry->e_key);hlist_bl_lock (head); +/* Now a reliable check if the entry didn't get used... */ +if (atomic_read (&entry->e_refcnt) >2 ) { +hlist_bl_unlock (head); +spin_lock (&cache->c_list_lock); +list_add_tail (&entry->e_list, &cache->c_list); + cache->c_entry_count++; +continue ; + }if (!hlist_bl_unhashed (&entry->e_hash_list)) {hlist_bl_del_init (&entry->e_hash_list);atomic_dec (&entry->e_refcnt);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 562/658 mbcache: add functions to delete entry if unused
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 3dc96bba65f53daa217f0a8f43edad145286a8f5 ]
Add function mb_cache_entry_delete_or_get() to delete mbcache entry if it is unused and also add a function to wait for entry to become unused
- mb_cache_entry_wait_unused(). We do not share code between the two deleting function as one of them will go away soon.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 66 +++++++++++++++++++++++++++++++++++++++-- include/linux/mbcache.h | 10 ++++++- 2 files changed, 73 insertions(+), 3 deletions(-)
fs/mbcache.c +64 -2
@@ -11,7 +11,7 @@/* * Mbcache is a simple key-value store. Keys need not be unique, however * key-value pairs are expected to be unique (we use this fact in -* mb_cache_entry_delete()). +* mb_cache_entry_delete_or_get()). * * Ext2 and ext4 use this cache for deduplication of extended attribute blocks. * Ext4 also uses it for deduplication of xattr values stored in inodes.
@@ -125,6 +125,19 @@ void __mb_cache_entry_free(struct mb_cache_entry *entry) }EXPORT_SYMBOL (__mb_cache_entry_free); +/* +* mb_cache_entry_wait_unused - wait to be the last user of the entry +* +* @entry - entry to work on +* +* Wait to be the last user of the entry. +*/ +void mb_cache_entry_wait_unused (struct mb_cache_entry *entry) +{ +wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=3 ); +} +EXPORT_SYMBOL (mb_cache_entry_wait_unused); +static struct mb_cache_entry *__entry_find (struct mb_cache *cache,struct mb_cache_entry *entry,u32 key)
@@ -217,7 +230,7 @@ struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, }EXPORT_SYMBOL (mb_cache_entry_get); -/* mb_cache_entry_delete - remove a cache entry +/* mb_cache_entry_delete - try to remove a cache entry * @cache - cache we work with * @key - key * @value - value
@@ -254,6 +267,55 @@ void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value) }EXPORT_SYMBOL (mb_cache_entry_delete); +/* mb_cache_entry_delete_or_get - remove a cache entry if it has no users +* @cache - cache we work with +* @key - key +* @value - value +* +* Remove entry from cache @cache with key @key and value @value. The removal +* happens only if the entry is unused. The function returns NULL in case the +* entry was successfully removed or there's no entry in cache. Otherwise the +* function grabs reference of the entry that we failed to delete because it +* still has users and return it. +*/ +struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache, +u32 key,u64 value) +{ +struct hlist_bl_node *node; +struct hlist_bl_head *head; +struct mb_cache_entry *entry; + + head =mb_cache_entry_head (cache, key); +hlist_bl_lock (head); +hlist_bl_for_each_entry (entry, node, head, e_hash_list) { +if (entry->e_key == key && entry->e_value == value) { +if (atomic_read (&entry->e_refcnt) >2 ) { +atomic_inc (&entry->e_refcnt); +hlist_bl_unlock (head); +return entry; + } +/* We keep hash list reference to keep entry alive */ +hlist_bl_del_init (&entry->e_hash_list); +hlist_bl_unlock (head); +spin_lock (&cache->c_list_lock); +if (!list_empty (&entry->e_list)) { +list_del_init (&entry->e_list); +if (!WARN_ONCE (cache->c_entry_count ==0 , +"mbcache: attempt to decrement c_entry_count past zero" )) + cache->c_entry_count--; +atomic_dec (&entry->e_refcnt); + } +spin_unlock (&cache->c_list_lock); +mb_cache_entry_put (cache, entry); +return NULL ; + } + } +hlist_bl_unlock (head); + +return NULL ; +} +EXPORT_SYMBOL (mb_cache_entry_delete_or_get); +/* mb_cache_entry_touch - cache entry got used * @cache - cache the entry belongs to * @entry - entry that got used
include/linux/mbcache.h +9 -1
@@ -30,15 +30,23 @@ void mb_cache_destroy(struct mb_cache *cache);int mb_cache_entry_create (struct mb_cache *cache,gfp_t mask,u32 key,u64 value,bool reusable);void __mb_cache_entry_free (struct mb_cache_entry *entry); +void mb_cache_entry_wait_unused (struct mb_cache_entry *entry);static inline int mb_cache_entry_put (struct mb_cache *cache,struct mb_cache_entry *entry) { -if (!atomic_dec_and_test (&entry->e_refcnt)) +unsigned int cnt =atomic_dec_return (&entry->e_refcnt); + +if (cnt >0 ) { +if (cnt <=3 ) +wake_up_var (&entry->e_refcnt);return 0 ; + }__mb_cache_entry_free (entry);return 1 ; } +struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache, +u32 key,u64 value);void mb_cache_entry_delete (struct mb_cache *cache,u32 key,u64 value);struct mb_cache_entry *mb_cache_entry_get (struct mb_cache *cache,u32 key,u64 value);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 563/658 ext4: remove EA inode entry from mbcache on inode eviction
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 6bc0d63dad7f9f54d381925ee855b402f652fa39 ]
Currently we remove EA inode from mbcache as soon as its xattr refcount drops to zero. However there can be pending attempts to reuse the inode and thus refcount handling code has to handle the situation when refcount increases from zero anyway. So save some work and just keep EA inode in mbcache until it is getting evicted. At that moment we are sure following iget() of EA inode will fail anyway (or wait for eviction to finish and load things from the disk again) and so removing mbcache entry at that moment is fine and simplifies the code a bit.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/inode.c | 2 ++ fs/ext4/xattr.c | 24 ++++++++---------------- fs/ext4/xattr.h | 1 + 3 files changed, 11 insertions(+), 16 deletions(-)
fs/ext4/inode.c +2 -0
@@ -207,6 +207,8 @@ void ext4_evict_inode(struct inode *inode)trace_ext4_evict_inode (inode); +if (EXT4_I (inode)->i_flags &EXT4_EA_INODE_FL ) +ext4_evict_ea_inode (inode);if (inode->i_nlink) {/* * When journalling data dirty buffers are tracked only in the
fs/ext4/xattr.c +8 -16
@@ -434,6 +434,14 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,return err; } +/* Remove entry from mbcache when EA inode is getting evicted */ +void ext4_evict_ea_inode (struct inode *inode) +{ +if (EA_INODE_CACHE (inode)) +mb_cache_entry_delete (EA_INODE_CACHE (inode), +ext4_xattr_inode_get_hash (inode), inode->i_ino); +} + static int ext4_xattr_inode_verify_hashes(struct inode *ea_inode, struct ext4_xattr_entry *entry, void *buffer,
@@ -1019,10 +1027,8 @@ static int ext4_xattr_ensure_credits(handle_t *handle, struct inode *inode,static int ext4_xattr_inode_update_ref (handle_t *handle,struct inode *ea_inode,int ref_change) { -struct mb_cache *ea_inode_cache =EA_INODE_CACHE (ea_inode);struct ext4_iloc iloc;s64 ref_count; -u32 hash;int ret;inode_lock (ea_inode);
@@ -1045,14 +1051,6 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,set_nlink (ea_inode,1 );ext4_orphan_del (handle, ea_inode); - -if (ea_inode_cache) { - hash =ext4_xattr_inode_get_hash (ea_inode); -mb_cache_entry_create (ea_inode_cache, -GFP_NOFS , hash, - ea_inode->i_ino, - true/* reusable */ ); - } } }else { WARN_ONCE(ref_count < 0, "EA inode %lu ref_count=%lld",
@@ -1065,12 +1063,6 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,clear_nlink (ea_inode);ext4_orphan_add (handle, ea_inode); - -if (ea_inode_cache) { - hash =ext4_xattr_inode_get_hash (ea_inode); -mb_cache_entry_delete (ea_inode_cache, hash, - ea_inode->i_ino); - } } }
fs/ext4/xattr.h +1 -0
@@ -190,6 +190,7 @@ extern void ext4_xattr_inode_array_free(struct ext4_xattr_inode_array *array);extern int ext4_expand_extra_isize_ea (struct inode *inode,int new_extra_isize,struct ext4_inode *raw_inode,handle_t *handle); +extern void ext4_evict_ea_inode (struct inode *inode);extern const struct xattr_handler *ext4_xattr_handlers[];
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 564/658 ext4: unindent codeblock in ext4_xattr_block_set()
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit fd48e9acdf26d0cbd80051de07d4a735d05d29b2 ]
Remove unnecessary else (and thus indentation level) from a code block in ext4_xattr_block_set(). It will also make following code changes easier. No functional changes.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 77 ++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 39 deletions(-)
fs/ext4/xattr.c +38 -39
@@ -1863,6 +1863,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,#define header (x) ((struct ext4_xattr_header *)(x))if (s->base) { +int offset = (char *)s->here - bs->bh->b_data; +BUFFER_TRACE (bs->bh,"get_write_access" ); error =ext4_journal_get_write_access (handle, bs->bh);if (error)
@@ -1894,49 +1896,46 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,if (error) goto cleanup; goto inserted; - }else { -int offset = (char *)s->here - bs->bh->b_data; + } +unlock_buffer (bs->bh); +ea_bdebug (bs->bh,"cloning" ); + s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); + error = -ENOMEM ; +if (s->base ==NULL ) + goto cleanup; + s->first =ENTRY (header (s->base)+1 ); +header (s->base)->h_refcount =cpu_to_le32 (1 ); + s->here =ENTRY (s->base + offset); + s->end = s->base + bs->bh->b_size; -unlock_buffer (bs->bh); -ea_bdebug (bs->bh,"cloning" ); - s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS ); - error = -ENOMEM ; -if (s->base ==NULL ) +/* +* If existing entry points to an xattr inode, we need +* to prevent ext4_xattr_set_entry() from decrementing +* ref count on it because the reference belongs to the +* original block. In this case, make the entry look +* like it has an empty value. +*/ +if (!s->not_found && s->here->e_value_inum) { + ea_ino =le32_to_cpu (s->here->e_value_inum); + error =ext4_xattr_inode_iget (inode, ea_ino, +le32_to_cpu (s->here->e_hash), + &tmp_inode); +if (error) goto cleanup; - s->first =ENTRY (header (s->base)+1 ); -header (s->base)->h_refcount =cpu_to_le32 (1 ); - s->here =ENTRY (s->base + offset); - s->end = s->base + bs->bh->b_size; -/* -* If existing entry points to an xattr inode, we need -* to prevent ext4_xattr_set_entry() from decrementing -* ref count on it because the reference belongs to the -* original block. In this case, make the entry look -* like it has an empty value. -*/ -if (!s->not_found && s->here->e_value_inum) { - ea_ino =le32_to_cpu (s->here->e_value_inum); - error =ext4_xattr_inode_iget (inode, ea_ino, -le32_to_cpu (s->here->e_hash), - &tmp_inode); -if (error) - goto cleanup; - -if (!ext4_test_inode_state (tmp_inode, -EXT4_STATE_LUSTRE_EA_INODE )) { -/* -* Defer quota free call for previous -* inode until success is guaranteed. -*/ - old_ea_inode_quota =le32_to_cpu ( - s->here->e_value_size); - } -iput (tmp_inode); - - s->here->e_value_inum =0 ; - s->here->e_value_size =0 ; +if (!ext4_test_inode_state (tmp_inode, +EXT4_STATE_LUSTRE_EA_INODE )) { +/* +* Defer quota free call for previous +* inode until success is guaranteed. +*/ + old_ea_inode_quota =le32_to_cpu ( + s->here->e_value_size); } +iput (tmp_inode); + + s->here->e_value_inum =0 ; + s->here->e_value_size =0 ; } }else {/* Allocate a buffer where we construct the new block. */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 565/658 ext4: fix race when reusing xattr blocks
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 65f8b80053a1b2fd602daa6814e62d6fa90e5e9b ]
When ext4_xattr_block_set() decides to remove xattr block the following race can happen:
CPU1 CPU2ext4_xattr_block_set() ext4_xattr_release_block()
new_bh = ext4_xattr_block_cache_find()
lock_buffer(bh);
ref = le32_to_cpu(BHDR(bh)->h_refcount);
if (ref == 1) {
...
mb_cache_entry_delete();
unlock_buffer(bh);
ext4_free_blocks();
...
ext4_forget(..., bh, ...);
jbd2_journal_revoke(..., bh); ext4_journal_get_write_access(..., new_bh, ...)
do_get_write_access()
jbd2_journal_cancel_revoke(..., new_bh);Later the code in ext4_xattr_block_set() finds out the block got freed and cancels reusal of the block but the revoke stays canceled and so in case of block reuse and journal replay the filesystem can get corrupted. If the race works out slightly differently, we can also hit assertions in the jbd2 code.
Fix the problem by making sure that once matching mbcache entry is found, code dropping the last xattr block reference (or trying to modify xattr block in place) waits until the mbcache entry reference is dropped. This way code trying to reuse xattr block is protected from someone trying to drop the last reference to xattr block.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/ext4/xattr.c | 67 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 22 deletions(-)
fs/ext4/xattr.c +45 -22
@@ -437,9 +437,16 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,/* Remove entry from mbcache when EA inode is getting evicted */ void ext4_evict_ea_inode (struct inode *inode) { -if (EA_INODE_CACHE (inode)) -mb_cache_entry_delete (EA_INODE_CACHE (inode), -ext4_xattr_inode_get_hash (inode), inode->i_ino); +struct mb_cache_entry *oe; + +if (!EA_INODE_CACHE (inode)) +return ; +/* Wait for entry to get unused so that we can remove it */ +while ((oe =mb_cache_entry_delete_or_get (EA_INODE_CACHE (inode), +ext4_xattr_inode_get_hash (inode), inode->i_ino))) { +mb_cache_entry_wait_unused (oe); +mb_cache_entry_put (EA_INODE_CACHE (inode), oe); + } } static int
@@ -1241,6 +1248,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,if (error) goto out; +retry_ref:lock_buffer (bh); hash =le32_to_cpu (BHDR (bh)->h_hash); ref =le32_to_cpu (BHDR (bh)->h_refcount);
@@ -1250,9 +1258,18 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,* This must happen under buffer lock for * ext4_xattr_block_set() to reliably detect freed block */ -if (ea_block_cache) -mb_cache_entry_delete (ea_block_cache, hash, - bh->b_blocknr); +if (ea_block_cache) { +struct mb_cache_entry *oe; + + oe =mb_cache_entry_delete_or_get (ea_block_cache, hash, + bh->b_blocknr); +if (oe) { +unlock_buffer (bh); +mb_cache_entry_wait_unused (oe); +mb_cache_entry_put (ea_block_cache, oe); + goto retry_ref; + } + }get_bh (bh);unlock_buffer (bh);
@@ -1879,9 +1896,20 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,* ext4_xattr_block_set() to reliably detect modified * block */ -if (ea_block_cache) -mb_cache_entry_delete (ea_block_cache, hash, - bs->bh->b_blocknr); +if (ea_block_cache) { +struct mb_cache_entry *oe; + + oe =mb_cache_entry_delete_or_get (ea_block_cache, + hash, bs->bh->b_blocknr); +if (oe) { +/* +* Xattr block is getting reused. Leave +* it alone. +*/ +mb_cache_entry_put (ea_block_cache, oe); + goto clone_block; + } + }ea_bdebug (bs->bh,"modifying in-place" ); error =ext4_xattr_set_entry (i, s, handle, inode, true/* is_block */ );
@@ -1897,6 +1925,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, goto cleanup; goto inserted; } +clone_block:unlock_buffer (bs->bh);ea_bdebug (bs->bh,"cloning" ); s->base =kmemdup (BHDR (bs->bh), bs->bh->b_size,GFP_NOFS );
@@ -2002,18 +2031,13 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,lock_buffer (new_bh);/* * We have to be careful about races with -* freeing, rehashing or adding references to -* xattr block. Once we hold buffer lock xattr -* block's state is stable so we can check -* whether the block got freed / rehashed or -* not. Since we unhash mbcache entry under -* buffer lock when freeing / rehashing xattr -* block, checking whether entry is still -* hashed is reliable. Same rules hold for -* e_reusable handling. +* adding references to xattr block. Once we +* hold buffer lock xattr block's state is +* stable so we can check the additional +* reference fits. */ -if (hlist_bl_unhashed (&ce->e_hash_list) || - !ce->e_reusable) { + ref =le32_to_cpu (BHDR (new_bh)->h_refcount) +1 ; +if (ref >EXT4_XATTR_REFCOUNT_MAX ) {/* * Undo everything and check mbcache * again.
@@ -2028,9 +2052,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, new_bh =NULL ; goto inserted; } - ref =le32_to_cpu (BHDR (new_bh)->h_refcount) +1 ;BHDR (new_bh)->h_refcount =cpu_to_le32 (ref); -if (ref >=EXT4_XATTR_REFCOUNT_MAX ) +if (ref ==EXT4_XATTR_REFCOUNT_MAX ) ce->e_reusable =0 ;ea_bdebug (new_bh,"reusing; refcount now=%d" , ref);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 566/658 mbcache: automatically delete entries from cache on freeing
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 307af6c879377c1c63e71cbdd978201f9c7ee8df ]
Use the fact that entries with elevated refcount are not removed from the hash and just move removal of the entry from the hash to the entry freeing time. When doing this we also change the generic code to hold one reference to the cache entry, not two of them, which makes code somewhat more obvious.
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
--- fs/mbcache.c | 108 +++++++++++++++------------------------- include/linux/mbcache.h | 24 ++++++--- 2 files changed, 55 insertions(+), 77 deletions(-)
fs/mbcache.c +39 -69
@@ -90,7 +90,7 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,return -ENOMEM ;INIT_LIST_HEAD (&entry->e_list); -/* One ref for hash, one ref returned */ +/* Initial hash reference */ atomic_set (&entry->e_refcnt,1 ); entry->e_key = key; entry->e_value = value;
@@ -106,21 +106,28 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key, } }hlist_bl_add_head (&entry->e_hash_list, head); -hlist_bl_unlock (head); - +/* +* Add entry to LRU list before it can be found by +* mb_cache_entry_delete() to avoid races +*/ spin_lock (&cache->c_list_lock);list_add_tail (&entry->e_list, &cache->c_list); -/* Grab ref for LRU list */ -atomic_inc (&entry->e_refcnt); cache->c_entry_count++;spin_unlock (&cache->c_list_lock); +hlist_bl_unlock (head);return 0 ; }EXPORT_SYMBOL (mb_cache_entry_create); -void __mb_cache_entry_free (struct mb_cache_entry *entry) +void __mb_cache_entry_free (struct mb_cache *cache,struct mb_cache_entry *entry) { +struct hlist_bl_head *head; + + head =mb_cache_entry_head (cache, entry->e_key); +hlist_bl_lock (head); +hlist_bl_del (&entry->e_hash_list); +hlist_bl_unlock (head);kmem_cache_free (mb_entry_cache, entry); }EXPORT_SYMBOL (__mb_cache_entry_free);
@@ -134,7 +141,7 @@ EXPORT_SYMBOL(__mb_cache_entry_free);*/ void mb_cache_entry_wait_unused (struct mb_cache_entry *entry) { -wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=3 ); +wait_var_event (&entry->e_refcnt,atomic_read (&entry->e_refcnt) <=2 ); }EXPORT_SYMBOL (mb_cache_entry_wait_unused);
@@ -155,10 +162,9 @@ static struct mb_cache_entry *__entry_find(struct mb_cache *cache,while (node) { entry = hlist_bl_entry(node, struct mb_cache_entry, e_hash_list); -if (entry->e_key == key && entry->e_reusable) { -atomic_inc (&entry->e_refcnt); +if (entry->e_key == key && entry->e_reusable && +atomic_inc_not_zero (&entry->e_refcnt)) goto out; - } node = node->next; } entry =NULL ;
@@ -218,10 +224,9 @@ struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, head =mb_cache_entry_head (cache, key);hlist_bl_lock (head);hlist_bl_for_each_entry (entry, node, head, e_hash_list) { -if (entry->e_key == key && entry->e_value == value) { -atomic_inc (&entry->e_refcnt); +if (entry->e_key == key && entry->e_value == value && +atomic_inc_not_zero (&entry->e_refcnt)) goto out; - } } entry =NULL ; out:
@@ -281,37 +286,25 @@ EXPORT_SYMBOL(mb_cache_entry_delete);struct mb_cache_entry *mb_cache_entry_delete_or_get (struct mb_cache *cache,u32 key,u64 value) { -struct hlist_bl_node *node; -struct hlist_bl_head *head;struct mb_cache_entry *entry; - head =mb_cache_entry_head (cache, key); -hlist_bl_lock (head); -hlist_bl_for_each_entry (entry, node, head, e_hash_list) { -if (entry->e_key == key && entry->e_value == value) { -if (atomic_read (&entry->e_refcnt) >2 ) { -atomic_inc (&entry->e_refcnt); -hlist_bl_unlock (head); -return entry; - } -/* We keep hash list reference to keep entry alive */ -hlist_bl_del_init (&entry->e_hash_list); -hlist_bl_unlock (head); -spin_lock (&cache->c_list_lock); -if (!list_empty (&entry->e_list)) { -list_del_init (&entry->e_list); -if (!WARN_ONCE (cache->c_entry_count ==0 , -"mbcache: attempt to decrement c_entry_count past zero" )) - cache->c_entry_count--; -atomic_dec (&entry->e_refcnt); - } -spin_unlock (&cache->c_list_lock); -mb_cache_entry_put (cache, entry); -return NULL ; - } - } -hlist_bl_unlock (head); + entry =mb_cache_entry_get (cache, key, value); +if (!entry) +return NULL ; +/* +* Drop the ref we got from mb_cache_entry_get() and the initial hash +* ref if we are the last user +*/ +if (atomic_cmpxchg (&entry->e_refcnt,2 ,0 ) !=2 ) +return entry; + +spin_lock (&cache->c_list_lock); +if (!list_empty (&entry->e_list)) +list_del_init (&entry->e_list); + cache->c_entry_count--; +spin_unlock (&cache->c_list_lock); +__mb_cache_entry_free (cache, entry);return NULL ; }EXPORT_SYMBOL (mb_cache_entry_delete_or_get);
@@ -343,42 +336,24 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, unsigned long nr_to_scan) {struct mb_cache_entry *entry; -struct hlist_bl_head *head;unsigned long shrunk =0 ;spin_lock (&cache->c_list_lock);while (nr_to_scan-- && !list_empty (&cache->c_list)) { entry =list_first_entry (&cache->c_list, struct mb_cache_entry, e_list); -if (entry->e_referenced ||atomic_read (&entry->e_refcnt) >2 ) { +/* Drop initial hash reference if there is no user */ +if (entry->e_referenced || +atomic_cmpxchg (&entry->e_refcnt,1 ,0 ) !=1 ) { entry->e_referenced =0 ;list_move_tail (&entry->e_list, &cache->c_list);continue ; }list_del_init (&entry->e_list); cache->c_entry_count--; -/* -* We keep LRU list reference so that entry doesn't go away -* from under us. -*/ spin_unlock (&cache->c_list_lock); - head =mb_cache_entry_head (cache, entry->e_key); -hlist_bl_lock (head); -/* Now a reliable check if the entry didn't get used... */ -if (atomic_read (&entry->e_refcnt) >2 ) { -hlist_bl_unlock (head); -spin_lock (&cache->c_list_lock); -list_add_tail (&entry->e_list, &cache->c_list); - cache->c_entry_count++; -continue ; - } -if (!hlist_bl_unhashed (&entry->e_hash_list)) { -hlist_bl_del_init (&entry->e_hash_list); -atomic_dec (&entry->e_refcnt); - } -hlist_bl_unlock (head); -if (mb_cache_entry_put (cache, entry)) - shrunk++; +__mb_cache_entry_free (cache, entry); + shrunk++;cond_resched ();spin_lock (&cache->c_list_lock); }
@@ -470,11 +445,6 @@ void mb_cache_destroy(struct mb_cache *cache)* point. */ list_for_each_entry_safe (entry, next, &cache->c_list, e_list) { -if (!hlist_bl_unhashed (&entry->e_hash_list)) { -hlist_bl_del_init (&entry->e_hash_list); -atomic_dec (&entry->e_refcnt); - }else -WARN_ON (1 );list_del (&entry->e_list);WARN_ON (atomic_read (&entry->e_refcnt) !=1 );mb_cache_entry_put (cache, entry);
include/linux/mbcache.h +16 -8
@@ -13,8 +13,16 @@ struct mb_cache;struct mb_cache_entry {/* List of entries in cache - protected by cache->c_list_lock */ struct list_head e_list; -/* Hash table list - protected by hash chain bitlock */ +/* +* Hash table list - protected by hash chain bitlock. The entry is +* guaranteed to be hashed while e_refcnt > 0. +*/ struct hlist_bl_node e_hash_list; +/* +* Entry refcount. Once it reaches zero, entry is unhashed and freed. +* While refcount > 0, the entry is guaranteed to stay in the hash and +* e.g. mb_cache_entry_try_delete() will fail. +*/ atomic_t e_refcnt;/* Key in hash - stable during lifetime of the entry */ u32 e_key;
@@ -29,20 +37,20 @@ void mb_cache_destroy(struct mb_cache *cache);int mb_cache_entry_create (struct mb_cache *cache,gfp_t mask,u32 key,u64 value,bool reusable); -void __mb_cache_entry_free (struct mb_cache_entry *entry); +void __mb_cache_entry_free (struct mb_cache *cache, +struct mb_cache_entry *entry);void mb_cache_entry_wait_unused (struct mb_cache_entry *entry); -static inline int mb_cache_entry_put (struct mb_cache *cache, -struct mb_cache_entry *entry) +static inline void mb_cache_entry_put (struct mb_cache *cache, +struct mb_cache_entry *entry) {unsigned int cnt =atomic_dec_return (&entry->e_refcnt);if (cnt >0 ) { -if (cnt <=3 ) +if (cnt <=2 )wake_up_var (&entry->e_refcnt); -return 0 ; +return ; } -__mb_cache_entry_free (entry); -return 1 ; +__mb_cache_entry_free (cache, entry); } struct mb_cache_entry *mb_cache_entry_delete_or_get(struct mb_cache *cache,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 567/658 ext4: fix deadlock due to mbcache entry corruption
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit a44e84a9b7764c72896f7241a0ec9ac7e7ef38dd ]
When manipulating xattr blocks, we can deadlock infinitely looping inside ext4_xattr_block_set() where we constantly keep finding xattr block for reuse in mbcache but we are unable to reuse it because its reference count is too big. This happens because cache entry for the xattr block is marked as reusable (e_reusable set) although its reference count is too big. When this inconsistency happens, this inconsistent state is kept indefinitely and so ext4_xattr_block_set() keeps retrying indefinitely.
The inconsistent state is caused by non-atomic update of e_reusable bit. e_reusable is part of a bitfield and e_reusable update can race with update of e_referenced bit in the same bitfield resulting in loss of one of the updates. Fix the problem by using atomic bitops instead.
This bug has been around for many years, but it became *much* easier to hit after commit 65f8b80053a1 ("ext4: fix race when reusing xattr blocks").
--- fs/ext4/xattr.c | 4 ++-- fs/mbcache.c | 14 ++++++++------ include/linux/mbcache.h | 9 +++++++-- 3 files changed, 17 insertions(+), 10 deletions(-)
fs/ext4/xattr.c +2 -2
@@ -1293,7 +1293,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode, ce =mb_cache_entry_get (ea_block_cache, hash, bh->b_blocknr);if (ce) { - ce->e_reusable =1 ; +set_bit (MBE_REUSABLE_B , &ce->e_flags);mb_cache_entry_put (ea_block_cache, ce); } }
@@ -2054,7 +2054,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, }BHDR (new_bh)->h_refcount =cpu_to_le32 (ref);if (ref ==EXT4_XATTR_REFCOUNT_MAX ) - ce->e_reusable =0 ; +clear_bit (MBE_REUSABLE_B , &ce->e_flags);ea_bdebug (new_bh,"reusing; refcount now=%d" , ref);ext4_xattr_block_csum_set (inode, new_bh);
fs/mbcache.c +8 -6
@@ -94,8 +94,9 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,atomic_set (&entry->e_refcnt,1 ); entry->e_key = key; entry->e_value = value; - entry->e_reusable = reusable; - entry->e_referenced =0 ; + entry->e_flags =0 ; +if (reusable) +set_bit (MBE_REUSABLE_B , &entry->e_flags); head =mb_cache_entry_head (cache, key);hlist_bl_lock (head);hlist_bl_for_each_entry (dup, dup_node, head, e_hash_list) {
@@ -162,7 +163,8 @@ static struct mb_cache_entry *__entry_find(struct mb_cache *cache,while (node) { entry = hlist_bl_entry(node, struct mb_cache_entry, e_hash_list); -if (entry->e_key == key && entry->e_reusable && +if (entry->e_key == key && +test_bit (MBE_REUSABLE_B , &entry->e_flags) &&atomic_inc_not_zero (&entry->e_refcnt)) goto out; node = node->next;
@@ -318,7 +320,7 @@ EXPORT_SYMBOL(mb_cache_entry_delete_or_get);void mb_cache_entry_touch (struct mb_cache *cache,struct mb_cache_entry *entry) { - entry->e_referenced =1 ; +set_bit (MBE_REFERENCED_B , &entry->e_flags); }EXPORT_SYMBOL (mb_cache_entry_touch);
@@ -343,9 +345,9 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, entry =list_first_entry (&cache->c_list, struct mb_cache_entry, e_list);/* Drop initial hash reference if there is no user */ -if (entry->e_referenced || +if (test_bit (MBE_REFERENCED_B , &entry->e_flags) ||atomic_cmpxchg (&entry->e_refcnt,1 ,0 ) !=1 ) { - entry->e_referenced =0 ; +clear_bit (MBE_REFERENCED_B , &entry->e_flags);list_move_tail (&entry->e_list, &cache->c_list);continue ; }
include/linux/mbcache.h +7 -2
@@ -10,6 +10,12 @@struct mb_cache ; +/* Cache entry flags */ +enum { +MBE_REFERENCED_B =0 , +MBE_REUSABLE_B +}; +struct mb_cache_entry {/* List of entries in cache - protected by cache->c_list_lock */ struct list_head e_list;
@@ -26,8 +32,7 @@ struct mb_cache_entry {atomic_t e_refcnt;/* Key in hash - stable during lifetime of the entry */ u32 e_key; - u32 e_referenced:1; - u32 e_reusable:1; +unsigned long e_flags;/* User provided value - stable during lifetime of the entry */ u64 e_value; };
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 568/658 SUNRPC: ensure the matching upcall is in-flight upon downcall
In reply to Greg Kroah-HartmanFrom: minoura makoto <[email protected]>
[ Upstream commit b18cba09e374637a0a3759d856a6bca94c133952 ]
Commit 9130b8dbc6ac ("SUNRPC: allow for upcalls for the same uid but different gss service") introduced auth argument to __gss_find_upcall(), but in gss_pipe_downcall() it was left as NULL since it (and auth->service) was not (yet) determined.
When multiple upcalls with the same uid and different service are ongoing, it could happen that __gss_find_upcall(), which returns the first match found in the pipe->in_downcall list, could not find the correct gss_msg corresponding to the downcall we are looking for. Moreover, it might return a msg which is not sent to rpc.gssd yet.
We could see mount.nfs process hung in D state with multiple mount.nfs are executed in parallel. The call trace below is of CentOS 7.9 kernel-3.10.0-1160.24.1.el7.x86_64 but we observed the same hang w/ elrepo kernel-ml-6.0.7-1.el7.
PID: 71258 TASK: ffff91ebd4be0000 CPU: 36 COMMAND: "mount.nfs"
#0 [ffff9203ca3234f8] __schedule at ffffffffa3b8899f
#1 [ffff9203ca323580] schedule at ffffffffa3b88eb9
#2 [ffff9203ca323590] gss_cred_init at ffffffffc0355818 [auth_rpcgss] #3 [ffff9203ca323658] rpcauth_lookup_credcache at ffffffffc0421ebc
[sunrpc]
#4 [ffff9203ca3236d8] gss_lookup_cred at ffffffffc0353633 [auth_rpcgss] #5 [ffff9203ca3236e8] rpcauth_lookupcred at ffffffffc0421581 [sunrpc] #6 [ffff9203ca323740] rpcauth_refreshcred at ffffffffc04223d3 [sunrpc] #7 [ffff9203ca3237a0] call_refresh at ffffffffc04103dc [sunrpc] #8 [ffff9203ca3237b8] __rpc_execute at ffffffffc041e1c9 [sunrpc] #9 [ffff9203ca323820] rpc_execute at ffffffffc0420a48 [sunrpc]
The scenario is like this. Let's say there are two upcalls for services A and B, A -> B in pipe->in_downcall, B -> A in pipe->pipe.
When rpc.gssd reads pipe to get the upcall msg corresponding to service B from pipe->pipe and then writes the response, in gss_pipe_downcall the msg corresponding to service A will be picked because only uid is used to find the msg and it is before the one for B in pipe->in_downcall. And the process waiting for the msg corresponding to service A will be woken up.
Actual scheduing of that process might be after rpc.gssd processes the next msg. In rpc_pipe_generic_upcall it clears msg->errno (for A). The process is scheduled to see gss_msg->ctx == NULL and gss_msg->msg.errno == 0, therefore it cannot break the loop in gss_create_upcall and is never woken up after that.
This patch adds a simple check to ensure that a msg which is not sent to rpc.gssd yet is not chosen as the matching upcall upon receiving a downcall.
--- include/linux/sunrpc/rpc_pipe_fs.h | 5 +++++ net/sunrpc/auth_gss/auth_gss.c | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)
include/linux/sunrpc/rpc_pipe_fs.h +5 -0
@@ -94,6 +94,11 @@ extern ssize_t rpc_pipe_generic_upcall(struct file *, struct rpc_pipe_msg *, char __user *, size_t);extern int rpc_queue_upcall (struct rpc_pipe *,struct rpc_pipe_msg *); +/* returns true if the msg is in-flight, i.e., already eaten by the peer */ +static inline bool rpc_msg_is_inflight (const struct rpc_pipe_msg *msg) { +return (msg->copied !=0 &&list_empty (&msg->list)); +} +struct rpc_clnt ;extern struct dentry *rpc_create_client_dir (struct dentry *,const char *,struct rpc_clnt *);extern int rpc_remove_client_dir (struct rpc_clnt *);
net/sunrpc/auth_gss/auth_gss.c +17 -2
@@ -301,7 +301,7 @@ __gss_find_upcall(struct rpc_pipe *pipe, kuid_t uid, const struct gss_auth *authlist_for_each_entry (pos, &pipe->in_downcall, list) {if (!uid_eq (pos->uid, uid))continue ; -if (auth && pos->auth->service != auth->service) +if (pos->auth->service != auth->service)continue ;refcount_inc (&pos->count);return pos;
@@ -683,6 +683,21 @@ gss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred)return err; } +static struct gss_upcall_msg * +gss_find_downcall (struct rpc_pipe *pipe,kuid_t uid) +{ +struct gss_upcall_msg *pos; +list_for_each_entry (pos, &pipe->in_downcall, list) { +if (!uid_eq (pos->uid, uid)) +continue ; +if (!rpc_msg_is_inflight (&pos->msg)) +continue ; +refcount_inc (&pos->count); +return pos; + } +return NULL ; +} +#define MSG_BUF_MAXSIZE 1024 static ssize_t
@@ -729,7 +744,7 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) err = -ENOENT ;/* Find a matching upcall */ spin_lock (&pipe->lock); - gss_msg =__gss_find_upcall (pipe, uid,NULL ); + gss_msg =gss_find_downcall (pipe, uid);if (gss_msg ==NULL ) {spin_unlock (&pipe->lock); goto err_put_ctx;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 569/658 bpf: pull before calling skb_postpull_rcsum()
In reply to Greg Kroah-HartmanFrom: Jakub Kicinski <[email protected]>
[ Upstream commit 54c3f1a81421f85e60ae2eaae7be3727a09916ee ]
Anand hit a BUG() when pulling off headers on egress to a SW tunnel. We get to skb_checksum_help() with an invalid checksum offset (commit d7ea0d9df2a6 ("net: remove two BUG() from skb_checksum_help()") converted those BUGs to WARN_ONs()).
He points out oddness in how skb_postpull_rcsum() gets used. Indeed looks like we should pull before "postpull", otherwise the CHECKSUM_PARTIAL fixup from skb_postpull_rcsum() will not be able to do its job:
if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_start_offset(skb) < 0) skb->ip_summed = CHECKSUM_NONE;
--- net/core/filter.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/core/filter.c +5 -2
@@ -2795,15 +2795,18 @@ static int bpf_skb_generic_push(struct sk_buff *skb, u32 off, u32 len)static int bpf_skb_generic_pop (struct sk_buff *skb,u32 off,u32 len) { +void *old_data; +/* skb_ensure_writable() is not needed here, as we're * already working on an uncloned skb. */ if (unlikely (!pskb_may_pull (skb, off + len)))return -ENOMEM ; -skb_postpull_rcsum (skb, skb->data + off, len); -memmove (skb->data + len, skb->data, off); + old_data = skb->data;__skb_pull (skb, len); +skb_postpull_rcsum (skb, old_data + off, len); +memmove (skb->data, old_data, off);return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 570/658 nfsd: shut down the NFSv4 state objects before the filecache
In reply to Greg Kroah-HartmanFrom: Jeff Layton <[email protected]>
[ Upstream commit 789e1e10f214c00ca18fc6610824c5b9876ba5f2 ]
Currently, we shut down the filecache before trying to clean up the stateids that depend on it. This leads to the kernel trying to free an nfsd_file twice, and a refcount overput on the nf_mark.
Change the shutdown procedure to tear down all of the stateids prior to shutting down the filecache.
--- fs/nfsd/nfssvc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfssvc.c +1 -1
@@ -420,8 +420,8 @@ static void nfsd_shutdown_net(struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); -nfsd_file_cache_shutdown_net (net);nfs4_state_shutdown_net (net); +nfsd_file_cache_shutdown_net (net);if (nn->lockd_up) {lockd_down (net); nn->lockd_up =0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 571/658 net: hns3: add interrupts re-initialization while doing VF FLR
In reply to Greg Kroah-HartmanFrom: Jie Wang <[email protected]>
[ Upstream commit 09e6b30eeb254f1818a008cace3547159e908dfd ]
Currently keep alive message between PF and VF may be lost and the VF is unalive in PF. So the VF will not do reset during PF FLR reset process. This would make the allocated interrupt resources of VF invalid and VF would't receive or respond to PF any more.
So this patch adds VF interrupts re-initialization during VF FLR for VF recovery in above cases.
--- drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +2 -1
@@ -2592,7 +2592,8 @@ static int hclgevf_pci_reset(struct hclgevf_dev *hdev)struct pci_dev *pdev = hdev->pdev;int ret =0 ; -if (hdev->reset_type ==HNAE3_VF_FULL_RESET && +if ((hdev->reset_type ==HNAE3_VF_FULL_RESET || + hdev->reset_type ==HNAE3_FLR_RESET ) &&test_bit (HCLGEVF_STATE_IRQ_INITED , &hdev->state)) {hclgevf_misc_irq_uninit (hdev);hclgevf_uninit_msi (hdev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 572/658 net: sched: fix memory leak in tcindex_set_parms
In reply to Greg Kroah-HartmanFrom: Hawkins Jiawei <[email protected]>
[ Upstream commit 399ab7fe0fa0d846881685fd4e57e9a8ef7559f7 ]
Syzkaller reports a memory leak as follows:
====================================
BUG: memory leak
unreferenced object 0xffff88810c287f00 (size 256):
comm "syz-executor105", pid 3600, jiffies 4294943292 (age 12.990s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff814cf9f0>] kmalloc_trace+0x20/0x90 mm/slab_common.c:1046
[<ffffffff839c9e07>] kmalloc include/linux/slab.h:576 [inline]
[<ffffffff839c9e07>] kmalloc_array include/linux/slab.h:627 [inline]
[<ffffffff839c9e07>] kcalloc include/linux/slab.h:659 [inline]
[<ffffffff839c9e07>] tcf_exts_init include/net/pkt_cls.h:250 [inline]
[<ffffffff839c9e07>] tcindex_set_parms+0xa7/0xbe0 net/sched/cls_tcindex.c:342
[<ffffffff839caa1f>] tcindex_change+0xdf/0x120 net/sched/cls_tcindex.c:553
[<ffffffff8394db62>] tc_new_tfilter+0x4f2/0x1100 net/sched/cls_api.c:2147
[<ffffffff8389e91c>] rtnetlink_rcv_msg+0x4dc/0x5d0 net/core/rtnetlink.c:6082
[<ffffffff839eba67>] netlink_rcv_skb+0x87/0x1d0 net/netlink/af_netlink.c:2540
[<ffffffff839eab87>] netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
[<ffffffff839eab87>] netlink_unicast+0x397/0x4c0 net/netlink/af_netlink.c:1345
[<ffffffff839eb046>] netlink_sendmsg+0x396/0x710 net/netlink/af_netlink.c:1921
[<ffffffff8383e796>] sock_sendmsg_nosec net/socket.c:714 [inline]
[<ffffffff8383e796>] sock_sendmsg+0x56/0x80 net/socket.c:734
[<ffffffff8383eb08>] ____sys_sendmsg+0x178/0x410 net/socket.c:2482
[<ffffffff83843678>] ___sys_sendmsg+0xa8/0x110 net/socket.c:2536
[<ffffffff838439c5>] __sys_sendmmsg+0x105/0x330 net/socket.c:2622
[<ffffffff83843c14>] __do_sys_sendmmsg net/socket.c:2651 [inline]
[<ffffffff83843c14>] __se_sys_sendmmsg net/socket.c:2648 [inline]
[<ffffffff83843c14>] __x64_sys_sendmmsg+0x24/0x30 net/socket.c:2648
[<ffffffff84605fd5>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
[<ffffffff84605fd5>] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
[<ffffffff84800087>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
====================================Kernel uses tcindex_change() to change an existing filter properties.
Yet the problem is that, during the process of changing, if old_r is retrieved from p->perfect, then kernel uses tcindex_alloc_perfect_hash() to newly allocate filter results, uses tcindex_filter_result_init() to clear the old filter result, without destroying its tcf_exts structure, which triggers the above memory leak.
To be more specific, there are only two source for the old_r, according to the tcindex_lookup(). old_r is retrieved from p->perfect, or old_r is retrieved from p->h.
* If old_r is retrieved from p->perfect, kernel usestcindex_alloc_perfect_hash() to newly allocate the
filter results. Then r is assigned with cp->perfect + handle, which is newly allocated. So condition old_r && old_r != r is true in this situation, and kernel uses tcindex_filter_result_init() to clear the old filter result, without destroying
its tcf_exts structure
* If old_r is retrieved from p->h, then p->perfect is NULL
according to the tcindex_lookup(). Considering that cp->h is directly copied from p->h and p->perfect is NULL, r is assigned with tcindex_lookup(cp, handle), whose value should be the same as old_r, so condition old_r && old_r != r is false in this situation, kernel ignores using tcindex_filter_result_init() to clear the old filter result.
So only when old_r is retrieved from p->perfect does kernel use tcindex_filter_result_init() to clear the old filter result, which triggers the above memory leak.
Considering that there already exists a tc_filter_wq workqueue to destroy the old tcindex_data by tcindex_partial_destroy_work() at the end of tcindex_set_parms(), this patch solves this memory leak bug by removing this old filter result clearing part and delegating it to the tc_filter_wq workqueue.
Note that this patch doesn't introduce any other issues. If old_r is retrieved from p->perfect, this patch just delegates old filter result clearing part to the tc_filter_wq workqueue; If old_r is retrieved from p->h, kernel doesn't reach the old filter result clearing part, so removing this part has no effect.
[Thanks to the suggestion from Jakub Kicinski, Cong Wang, Paolo Abeni and Dmitry Vyukov]
--- net/sched/cls_tcindex.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
net/sched/cls_tcindex.c +2 -10
@@ -332,7 +332,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, struct tcindex_filter_result *r, struct nlattr **tb, struct nlattr *est, bool ovr, struct netlink_ext_ack *extack) { - struct tcindex_filter_result new_filter_result, *old_r = r; + struct tcindex_filter_result new_filter_result;struct tcindex_data *cp =NULL , *oldp;struct tcindex_filter *f =NULL ;/* make gcc behave */ struct tcf_result cr = {};
@@ -401,7 +401,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, err =tcindex_filter_result_init (&new_filter_result, cp, net);if (err <0 ) goto errout_alloc; -if (old_r) +if (r) cr = r->res; err = -EBUSY ;
@@ -478,14 +478,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,tcf_bind_filter (tp, &cr, base); } -if (old_r && old_r != r) { - err =tcindex_filter_result_init (old_r, cp, net); -if (err <0 ) { -kfree (f); - goto errout_alloc; - } - } - oldp = p; r->res = cr;tcf_exts_change (&r->exts, &e);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 573/658 qlcnic: prevent ->dcb use-after-free on qlcnic_dcb_enable() failure
In reply to Greg Kroah-HartmanFrom: Daniil Tatianin <[email protected]>
[ Upstream commit 13a7c8964afcd8ca43c0b6001ebb0127baa95362 ]
adapter->dcb would get silently freed inside qlcnic_dcb_enable() in case qlcnic_dcb_attach() would return an error, which always happens under OOM conditions. This would lead to use-after-free because both of the existing callers invoke qlcnic_dcb_get_info() on the obtained pointer, which is potentially freed at that point.
Propagate errors from qlcnic_dcb_enable(), and instead free the dcb pointer at callsite using qlcnic_dcb_free(). This also removes the now unused qlcnic_clear_dcb_ops() helper, which was a simple wrapper around kfree() also causing memory leaks for partially initialized dcb.
Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.
--- drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c | 8 +++++++- drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h | 10 ++-------- drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 8 +++++++- 3 files changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c +7 -1
@@ -2525,7 +2525,13 @@ int qlcnic_83xx_init(struct qlcnic_adapter *adapter, int pci_using_dac) goto disable_mbx_intr;qlcnic_83xx_clear_function_resources (adapter); -qlcnic_dcb_enable (adapter->dcb); + + err =qlcnic_dcb_enable (adapter->dcb); +if (err) { +qlcnic_dcb_free (adapter->dcb); + goto disable_mbx_intr; + } +qlcnic_83xx_initialize_nic (adapter,1 );qlcnic_dcb_get_info (adapter->dcb);
drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.h +2 -8
@@ -42,11 +42,6 @@ struct qlcnic_dcb {unsigned long state; }; -static inline void qlcnic_clear_dcb_ops (struct qlcnic_dcb *dcb) -{ -kfree (dcb); -} -static inline int qlcnic_dcb_get_hw_capability (struct qlcnic_dcb *dcb) {if (dcb && dcb->ops->get_hw_capability)
@@ -113,9 +108,8 @@ static inline void qlcnic_dcb_init_dcbnl_ops(struct qlcnic_dcb *dcb) dcb->ops->init_dcbnl_ops(dcb); } -static inline void qlcnic_dcb_enable (struct qlcnic_dcb *dcb) +static inline int qlcnic_dcb_enable (struct qlcnic_dcb *dcb) { -if (dcb &&qlcnic_dcb_attach (dcb)) -qlcnic_clear_dcb_ops (dcb); +return dcb ?qlcnic_dcb_attach (dcb) :0 ; }#endif
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +7 -1
@@ -2639,7 +2639,13 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) "Device does not support MSI interrupts\n");if (qlcnic_82xx_check (adapter)) { -qlcnic_dcb_enable (adapter->dcb); + err =qlcnic_dcb_enable (adapter->dcb); +if (err) { +qlcnic_dcb_free (adapter->dcb); +dev_err (&pdev->dev,"Failed to enable DCB\n" ); + goto err_out_free_hw; + } +qlcnic_dcb_get_info (adapter->dcb); err =qlcnic_setup_intr (adapter);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 574/658 nfc: Fix potential resource leaks
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit df49908f3c52d211aea5e2a14a93bbe67a2cb3af ]
nfc_get_device() take reference for the device, add missing nfc_put_device() to release it when not need anymore. Also fix the style warnning by use error EOPNOTSUPP instead of ENOTSUPP.
--- net/nfc/netlink.c | 52 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-)
net/nfc/netlink.c +38 -14
@@ -1505,6 +1505,7 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)u32 dev_idx, se_idx;u8 *apdu;size_t apdu_len; +int rc; if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || !info->attrs[NFC_ATTR_SE_INDEX] ||
@@ -1518,25 +1519,37 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)if (!dev)return -ENODEV ; -if (!dev->ops || !dev->ops->se_io) -return -ENOTSUPP ; +if (!dev->ops || !dev->ops->se_io) { + rc = -EOPNOTSUPP ; + goto put_dev; + } apdu_len =nla_len (info->attrs[NFC_ATTR_SE_APDU ]); -if (apdu_len ==0 ) -return -EINVAL ; +if (apdu_len ==0 ) { + rc = -EINVAL ; + goto put_dev; + } apdu =nla_data (info->attrs[NFC_ATTR_SE_APDU ]); -if (!apdu) -return -EINVAL ; +if (!apdu) { + rc = -EINVAL ; + goto put_dev; + } ctx =kzalloc (sizeof (struct se_io_ctx ),GFP_KERNEL ); -if (!ctx) -return -ENOMEM ; +if (!ctx) { + rc = -ENOMEM ; + goto put_dev; + } ctx->dev_idx = dev_idx; ctx->se_idx = se_idx; -return nfc_se_io (dev, se_idx, apdu, apdu_len, se_io_cb, ctx); + rc =nfc_se_io (dev, se_idx, apdu, apdu_len, se_io_cb, ctx); + +put_dev: +nfc_put_device (dev); +return rc; } static int nfc_genl_vendor_cmd(struct sk_buff *skb,
@@ -1559,14 +1572,21 @@ static int nfc_genl_vendor_cmd(struct sk_buff *skb, subcmd =nla_get_u32 (info->attrs[NFC_ATTR_VENDOR_SUBCMD ]); dev =nfc_get_device (dev_idx); -if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds) +if (!dev)return -ENODEV ; +if (!dev->vendor_cmds || !dev->n_vendor_cmds) { + err = -ENODEV ; + goto put_dev; + } +if (info->attrs[NFC_ATTR_VENDOR_DATA ]) { data =nla_data (info->attrs[NFC_ATTR_VENDOR_DATA ]); data_len =nla_len (info->attrs[NFC_ATTR_VENDOR_DATA ]); -if (data_len ==0 ) -return -EINVAL ; +if (data_len ==0 ) { + err = -EINVAL ; + goto put_dev; + } }else { data =NULL ; data_len =0 ;
@@ -1581,10 +1601,14 @@ static int nfc_genl_vendor_cmd(struct sk_buff *skb, dev->cur_cmd_info = info; err = cmd->doit (dev, data, data_len); dev->cur_cmd_info =NULL ; -return err; + goto put_dev; } -return -EOPNOTSUPP ; + err = -EOPNOTSUPP ; + +put_dev: +nfc_put_device (dev); +return err; }/* message building helper */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 575/658 vhost: fix range used in translate_desc()
In reply to Greg Kroah-HartmanFrom: Stefano Garzarella <[email protected]>
[ Upstream commit 98047313cdb46828093894d0ac8b1183b8b317f9 ]
vhost_iotlb_itree_first() requires start and last parameters to search for a mapping that overlaps the range.
In translate_desc() we cyclically call vhost_iotlb_itree_first(), incrementing addr by the amount already translated, so rightly we move the start parameter passed to vhost_iotlb_itree_first(), but we should hold the last parameter constant.
Let's fix it by saving the last parameter value before incrementing addr in the loop.
Message-Id: <[email protected]>
--- drivers/vhost/vhost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +2 -2
@@ -2050,7 +2050,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,struct vhost_dev *dev = vq->dev;struct vhost_umem *umem = dev->iotlb ? dev->iotlb : dev->umem;struct iovec *_iov; -u64 s =0 ; +u64 s =0 , last = addr + len -1 ;int ret =0 ;while ((u64 )len > s) {
@@ -2061,7 +2061,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len, } node =vhost_umem_interval_tree_iter_first (&umem->umem_tree, - addr, addr + len -1 ); + addr, last);if (node ==NULL || node->start > addr) {if (umem != dev->iotlb) { ret = -EFAULT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 576/658 net: amd-xgbe: add missed tasklet_kill
In reply to Greg Kroah-HartmanFrom: Jiguang Xiao <[email protected]>
[ Upstream commit d530ece70f16f912e1d1bfeea694246ab78b0a4b ]
The driver does not call tasklet_kill in several places. Add the calls to fix it.
--- drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 3 +++ drivers/net/ethernet/amd/xgbe/xgbe-i2c.c | 4 +++- drivers/net/ethernet/amd/xgbe/xgbe-mdio.c | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-drv.c +3 -0
@@ -1139,6 +1139,9 @@ static void xgbe_free_irqs(struct xgbe_prv_data *pdata)devm_free_irq (pdata->dev, pdata->dev_irq, pdata); +tasklet_kill (&pdata->tasklet_dev); +tasklet_kill (&pdata->tasklet_ecc); +if (pdata->vdata->ecc_support && (pdata->dev_irq != pdata->ecc_irq))devm_free_irq (pdata->dev, pdata->ecc_irq, pdata);
drivers/net/ethernet/amd/xgbe/xgbe-i2c.c +3 -1
@@ -447,8 +447,10 @@ static void xgbe_i2c_stop(struct xgbe_prv_data *pdata)xgbe_i2c_disable (pdata);xgbe_i2c_clear_all_interrupts (pdata); -if (pdata->dev_irq != pdata->i2c_irq) +if (pdata->dev_irq != pdata->i2c_irq) {devm_free_irq (pdata->dev, pdata->i2c_irq, pdata); +tasklet_kill (&pdata->tasklet_i2c); + } }static int xgbe_i2c_start (struct xgbe_prv_data *pdata)
drivers/net/ethernet/amd/xgbe/xgbe-mdio.c +3 -1
@@ -1390,8 +1390,10 @@ static void xgbe_phy_stop(struct xgbe_prv_data *pdata)/* Disable auto-negotiation */ xgbe_an_disable_all (pdata); -if (pdata->dev_irq != pdata->an_irq) +if (pdata->dev_irq != pdata->an_irq) {devm_free_irq (pdata->dev, pdata->an_irq, pdata); +tasklet_kill (&pdata->tasklet_an); + } pdata->phy_if.phy_impl.stop (pdata);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 577/658 net: phy: xgmiitorgmii: Fix refcount leak in xgmiitorgmii_probe
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit d039535850ee47079d59527e96be18d8e0daa84b ]
of_phy_find_device() return device node with refcount incremented. Call put_device() to relese it when not needed anymore.
--- drivers/net/phy/xilinx_gmii2rgmii.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/phy/xilinx_gmii2rgmii.c +1 -0
@@ -82,6 +82,7 @@ static int xgmiitorgmii_probe(struct mdio_device *mdiodev)if (!priv->phy_dev->drv) {dev_info (dev,"Attached phy not ready\n" ); +put_device (&priv->phy_dev->mdio.dev);return -EPROBE_DEFER ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 578/658 RDMA/uverbs: Silence shiftTooManyBitsSigned warning
In reply to Greg Kroah-HartmanFrom: Leon Romanovsky <[email protected]>
[ Upstream commit 9b8d846924856570625b93f83ae0624391193bce ]
Fix reported by kbuild warning.
drivers/infiniband/core/uverbs_cmd.c:1897:47: warning: Shifting signed 32-bit value by 31 bits is undefined behaviour [shiftTooManyBitsSigned]
BUILD_BUG_ON(IB_USER_LAST_QP_ATTR_MASK == (1 << 31));
^Stable-dep-of: 8de8482fe573 ("RDMA/mlx5: Fix validation of max_rd_atomic caps for DC")
--- drivers/infiniband/core/uverbs_cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/uverbs_cmd.c +1 -1
@@ -1952,7 +1952,7 @@ static int ib_uverbs_ex_modify_qp(struct uverbs_attr_bundle *attrs)* Last bit is reserved for extending the attr_mask by * using another field. */ -BUILD_BUG_ON (IB_USER_LAST_QP_ATTR_MASK == (1 <<31 )); +BUILD_BUG_ON (IB_USER_LAST_QP_ATTR_MASK == (1ULL <<31 ));if (cmd.base.attr_mask & ~((IB_USER_LAST_QP_ATTR_MASK <<1 ) -1 ))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 579/658 RDMA/mlx5: Fix validation of max_rd_atomic caps for DC
In reply to Greg Kroah-HartmanFrom: Maor Gottlieb <[email protected]>
[ Upstream commit 8de8482fe5732fbef4f5af82bc0c0362c804cd1f ]
Currently, when modifying DC, we validate max_rd_atomic user attribute against the RC cap, validate against DC. RC and DC QP types have different device limitations.
This can cause userspace created DC QPs to malfunction.
--- drivers/infiniband/hw/mlx5/qp.c | 49 +++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +35 -14
@@ -3890,6 +3890,40 @@ static int mlx5_ib_modify_dct(struct ib_qp *ibqp, struct ib_qp_attr *attr,return err; } +static int validate_rd_atomic (struct mlx5_ib_dev *dev,struct ib_qp_attr *attr, +int attr_mask,enum ib_qp_type qp_type) +{ +int log_max_ra_res; +int log_max_ra_req; + +if (qp_type ==MLX5_IB_QPT_DCI ) { + log_max_ra_res =1 <<MLX5_CAP_GEN (dev->mdev, + log_max_ra_res_dc); + log_max_ra_req =1 <<MLX5_CAP_GEN (dev->mdev, + log_max_ra_req_dc); + }else { + log_max_ra_res =1 <<MLX5_CAP_GEN (dev->mdev, + log_max_ra_res_qp); + log_max_ra_req =1 <<MLX5_CAP_GEN (dev->mdev, + log_max_ra_req_qp); + } + +if (attr_mask &IB_QP_MAX_QP_RD_ATOMIC && + attr->max_rd_atomic > log_max_ra_res) { +mlx5_ib_dbg (dev,"invalid max_rd_atomic value %d\n" , + attr->max_rd_atomic); +return false; + } + +if (attr_mask &IB_QP_MAX_DEST_RD_ATOMIC && + attr->max_dest_rd_atomic > log_max_ra_req) { +mlx5_ib_dbg (dev,"invalid max_dest_rd_atomic value %d\n" , + attr->max_dest_rd_atomic); +return false; + } +return true; +} +int mlx5_ib_modify_qp (struct ib_qp *ibqp,struct ib_qp_attr *attr,int attr_mask,struct ib_udata *udata) {
@@ -3986,21 +4020,8 @@ int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, } } -if (attr_mask &IB_QP_MAX_QP_RD_ATOMIC && - attr->max_rd_atomic > - (1 <<MLX5_CAP_GEN (dev->mdev, log_max_ra_res_qp))) { -mlx5_ib_dbg (dev,"invalid max_rd_atomic value %d\n" , - attr->max_rd_atomic); - goto out; - } - -if (attr_mask &IB_QP_MAX_DEST_RD_ATOMIC && - attr->max_dest_rd_atomic > - (1 <<MLX5_CAP_GEN (dev->mdev, log_max_ra_req_qp))) { -mlx5_ib_dbg (dev,"invalid max_dest_rd_atomic value %d\n" , - attr->max_dest_rd_atomic); +if (!validate_rd_atomic (dev, attr, attr_mask, qp_type)) goto out; - }if (cur_state == new_state && cur_state ==IB_QPS_RESET ) { err =0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 580/658 net: sched: atm: dont intepret cls results when asked to drop
In reply to Greg Kroah-HartmanFrom: Jamal Hadi Salim <[email protected]>
[ Upstream commit a2965c7be0522eaa18808684b7b82b248515511b ]
If asked to drop a packet via TC_ACT_SHOT it is unsafe to assume res.class contains a valid pointer
--- net/sched/sch_atm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/sched/sch_atm.c +4 -1
@@ -396,10 +396,13 @@ static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch, result =tcf_classify (skb, fl, &res, true);if (result <0 )continue ; +if (result ==TC_ACT_SHOT ) + goto done; + flow = (struct atm_flow_data *)res.class;if (!flow) flow =lookup_flow (sch, res.classid); - goto done; + goto drop; } } flow =NULL ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 581/658 net: sched: cbq: dont intepret cls results when asked to drop
In reply to Greg Kroah-HartmanFrom: Jamal Hadi Salim <[email protected]>
[ Upstream commit caa4b35b4317d5147b3ab0fbdc9c075c7d2e9c12 ]
If asked to drop a packet via TC_ACT_SHOT it is unsafe to assume that res.class contains a valid pointer
Sample splat reported by Kyle Zeng
[ 5.405624] 0: reclassify loop, rule prio 0, protocol 800 [ 5.406326] ================================================================== [ 5.407240] BUG: KASAN: slab-out-of-bounds in cbq_enqueue+0x54b/0xea0 [ 5.407987] Read of size 1 at addr ffff88800e3122aa by task poc/299 [ 5.408731] [ 5.408897] CPU: 0 PID: 299 Comm: poc Not tainted 5.10.155+ #15 [ 5.409516] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 [ 5.410439] Call Trace: [ 5.410764] dump_stack+0x87/0xcd [ 5.411153] print_address_description+0x7a/0x6b0 [ 5.411687] ? vprintk_func+0xb9/0xc0 [ 5.411905] ? printk+0x76/0x96 [ 5.412110] ? cbq_enqueue+0x54b/0xea0 [ 5.412323] kasan_report+0x17d/0x220 [ 5.412591] ? cbq_enqueue+0x54b/0xea0 [ 5.412803] __asan_report_load1_noabort+0x10/0x20 [ 5.413119] cbq_enqueue+0x54b/0xea0 [ 5.413400] ? __kasan_check_write+0x10/0x20 [ 5.413679] __dev_queue_xmit+0x9c0/0x1db0 [ 5.413922] dev_queue_xmit+0xc/0x10 [ 5.414136] ip_finish_output2+0x8bc/0xcd0 [ 5.414436] __ip_finish_output+0x472/0x7a0 [ 5.414692] ip_finish_output+0x5c/0x190 [ 5.414940] ip_output+0x2d8/0x3c0 [ 5.415150] ? ip_mc_finish_output+0x320/0x320 [ 5.415429] __ip_queue_xmit+0x753/0x1760 [ 5.415664] ip_queue_xmit+0x47/0x60 [ 5.415874] __tcp_transmit_skb+0x1ef9/0x34c0 [ 5.416129] tcp_connect+0x1f5e/0x4cb0 [ 5.416347] tcp_v4_connect+0xc8d/0x18c0 [ 5.416577] __inet_stream_connect+0x1ae/0xb40 [ 5.416836] ? local_bh_enable+0x11/0x20 [ 5.417066] ? lock_sock_nested+0x175/0x1d0 [ 5.417309] inet_stream_connect+0x5d/0x90 [ 5.417548] ? __inet_stream_connect+0xb40/0xb40 [ 5.417817] __sys_connect+0x260/0x2b0 [ 5.418037] __x64_sys_connect+0x76/0x80 [ 5.418267] do_syscall_64+0x31/0x50 [ 5.418477] entry_SYSCALL_64_after_hwframe+0x61/0xc6 [ 5.418770] RIP: 0033:0x473bb7 [ 5.418952] Code: 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 2a 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 51 c3 48 83 ec 18 89 54 24 0c 48 89 34 24 89 [ 5.420046] RSP: 002b:00007fffd20eb0f8 EFLAGS: 00000246 ORIG_RAX: 000000000000002a [ 5.420472] RAX: ffffffffffffffda RBX: 00007fffd20eb578 RCX: 0000000000473bb7 [ 5.420872] RDX: 0000000000000010 RSI: 00007fffd20eb110 RDI: 0000000000000007 [ 5.421271] RBP: 00007fffd20eb150 R08: 0000000000000001 R09: 0000000000000004 [ 5.421671] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001 [ 5.422071] R13: 00007fffd20eb568 R14: 00000000004fc740 R15: 0000000000000002 [ 5.422471] [ 5.422562] Allocated by task 299: [ 5.422782] __kasan_kmalloc+0x12d/0x160 [ 5.423007] kasan_kmalloc+0x5/0x10 [ 5.423208] kmem_cache_alloc_trace+0x201/0x2e0 [ 5.423492] tcf_proto_create+0x65/0x290 [ 5.423721] tc_new_tfilter+0x137e/0x1830 [ 5.423957] rtnetlink_rcv_msg+0x730/0x9f0 [ 5.424197] netlink_rcv_skb+0x166/0x300 [ 5.424428] rtnetlink_rcv+0x11/0x20 [ 5.424639] netlink_unicast+0x673/0x860 [ 5.424870] netlink_sendmsg+0x6af/0x9f0 [ 5.425100] __sys_sendto+0x58d/0x5a0 [ 5.425315] __x64_sys_sendto+0xda/0xf0 [ 5.425539] do_syscall_64+0x31/0x50 [ 5.425764] entry_SYSCALL_64_after_hwframe+0x61/0xc6 [ 5.426065] [ 5.426157] The buggy address belongs to the object at ffff88800e312200 [ 5.426157] which belongs to the cache kmalloc-128 of size 128 [ 5.426955] The buggy address is located 42 bytes to the right of [ 5.426955] 128-byte region [ffff88800e312200, ffff88800e312280) [ 5.427688] The buggy address belongs to the page: [ 5.427992] page:000000009875fabc refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0xe312 [ 5.428562] flags: 0x100000000000200(slab) [ 5.428812] raw: 0100000000000200 dead000000000100 dead000000000122 ffff888007843680 [ 5.429325] raw: 0000000000000000 0000000000100010 00000001ffffffff ffff88800e312401 [ 5.429875] page dumped because: kasan: bad access detected [ 5.430214] page->mem_cgroup:ffff88800e312401 [ 5.430471] [ 5.430564] Memory state around the buggy address: [ 5.430846] ffff88800e312180: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 5.431267] ffff88800e312200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fc [ 5.431705] >ffff88800e312280: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 5.432123] ^ [ 5.432391] ffff88800e312300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fc [ 5.432810] ffff88800e312380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 5.433229] ================================================================== [ 5.433648] Disabling lock debugging due to kernel taint
--- net/sched/sch_cbq.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/sched/sch_cbq.c +3 -2
@@ -231,6 +231,8 @@ cbq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) result =tcf_classify (skb, fl, &res, true);if (!fl || result <0 ) goto fallback; +if (result ==TC_ACT_SHOT ) +return NULL ; cl = (void *)res.class;if (!cl) {
@@ -251,8 +253,7 @@ cbq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)case TC_ACT_TRAP : *qerr =NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;/* fall through */ -case TC_ACT_SHOT : -return NULL ; + fallthrough;case TC_ACT_RECLASSIFY :return cbq_reclassify (skb, cl); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 582/658 perf tools: Fix resources leak in perf_data__open_dir()
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit 0a6564ebd953c4590663c9a3c99a3ea9920ade6f ]
In perf_data__open_dir(), opendir() opens the directory stream. Add missing closedir() to release it after use.
--- tools/perf/util/data.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/data.c +2 -0
@@ -120,6 +120,7 @@ int perf_data__open_dir(struct perf_data *data) file->size = st.st_size; } +closedir (dir);if (!files)return -EINVAL ;
@@ -128,6 +129,7 @@ int perf_data__open_dir(struct perf_data *data)return 0 ; out_err: +closedir (dir);close_dir (files, nr);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 583/658 drivers/net/bonding/bond_3ad: return when theres no aggregator
In reply to Greg Kroah-HartmanFrom: Daniil Tatianin <[email protected]>
[ Upstream commit 9c807965483f42df1d053b7436eedd6cf28ece6f ]
Otherwise we would dereference a NULL aggregator pointer when calling __set_agg_ports_ready on the line below.
Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.
--- drivers/net/bonding/bond_3ad.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/bonding/bond_3ad.c +1 -0
@@ -1529,6 +1529,7 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr)slave_err (bond->dev, port->slave->dev,"Port %d did not find a suitable aggregator\n" , port->actor_port_number); +return ; } }/* if all aggregator's ports are READY_N == TRUE, set ready=TRUE
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 584/658 usb: rndis_host: Secure rndis_query check against int overflow
In reply to Greg Kroah-HartmanFrom: Szymon Heidrich <[email protected]>
[ Upstream commit c7dd13805f8b8fc1ce3b6d40f6aff47e66b72ad2 ]
Variables off and len typed as uint32 in rndis_query function are controlled by incoming RNDIS response message thus their value may be manipulated. Setting off to a unexpectetly large value will cause the sum with len and 8 to overflow and pass the implemented validation step. Consequently the response pointer will be referring to a location past the expected buffer boundaries allowing information leakage e.g. via RNDIS_OID_802_3_PERMANENT_ADDRESS OID.
--- drivers/net/usb/rndis_host.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/usb/rndis_host.c +2 -1
@@ -255,7 +255,8 @@ static int rndis_query(struct usbnet *dev, struct usb_interface *intf, off =le32_to_cpu (u.get_c->offset); len =le32_to_cpu (u.get_c->len); -if (unlikely ((8 + off + len) >CONTROL_BUFFER_SIZE )) +if (unlikely ((off >CONTROL_BUFFER_SIZE -8 ) || + (len >CONTROL_BUFFER_SIZE -8 - off))) goto response_error;if (*reply_len !=-1 && len != *reply_len)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 585/658 drm/i915: unpin on error in intel_vgpu_shadow_mm_pin()
In reply to Greg Kroah-HartmanFrom: Dan Carpenter <[email protected]>
[ Upstream commit 3792fc508c095abd84b10ceae12bd773e61fdc36 ]
Call intel_vgpu_unpin_mm() on this error path.
--- drivers/gpu/drm/i915/gvt/scheduler.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/i915/gvt/scheduler.c +1 -0
@@ -632,6 +632,7 @@ static int prepare_workload(struct intel_vgpu_workload *workload)if (workload->shadow_mm->type !=INTEL_GVT_MM_PPGTT || !workload->shadow_mm->ppgtt_mm.shadowed) { +intel_vgpu_unpin_mm (workload->shadow_mm);gvt_vgpu_err ("workload shadow ppgtt isn't ready\n" );return -EINVAL ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 586/658 caif: fix memory leak in cfctrl_linkup_request()
In reply to Greg Kroah-HartmanFrom: Zhengchao Shao <[email protected]>
[ Upstream commit fe69230f05897b3de758427b574fc98025dfc907 ]
When linktype is unknown or kzalloc failed in cfctrl_linkup_request(), pkt is not released. Add release process to error path.
--- net/caif/cfctrl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/caif/cfctrl.c +5 -1
@@ -269,11 +269,15 @@ int cfctrl_linkup_request(struct cflayer *layer,default :pr_warn ("Request setup of bad link type = %d\n" , param->linktype); +cfpkt_destroy (pkt);return -EINVAL ; } req =kzalloc (sizeof (*req),GFP_KERNEL ); -if (!req) +if (!req) { +cfpkt_destroy (pkt);return -ENOMEM ; + } + req->client_layer = user_layer; req->cmd =CFCTRL_CMD_LINK_SETUP ; req->param = *param;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 587/658 udf: Fix extension of the last extent in the file
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 83c7423d1eb6806d13c521d1002cc1a012111719 ]
When extending the last extent in the file within the last block, we wrongly computed the length of the last extent. This is mostly a cosmetical problem since the extent does not contain any data and the length will be fixed up by following operations but still.
--- fs/udf/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/udf/inode.c +1 -1
@@ -602,7 +602,7 @@ static void udf_do_extend_final_block(struct inode *inode,*/ if (new_elen <= (last_ext->extLength &UDF_EXTENT_LENGTH_MASK ))return ; - added_bytes = (last_ext->extLength &UDF_EXTENT_LENGTH_MASK ) - new_elen; + added_bytes = new_elen - (last_ext->extLength &UDF_EXTENT_LENGTH_MASK ); last_ext->extLength += added_bytes;UDF_I (inode)->i_lenExtents += added_bytes;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 588/658 ASoC: Intel: bytcr_rt5640: Add quirk for the Advantech MICA-071 tablet
In reply to Greg Kroah-HartmanFrom: Hans de Goede <[email protected]>
[ Upstream commit a1dec9d70b6ad97087b60b81d2492134a84208c6 ]
The Advantech MICA-071 tablet deviates from the defaults for a non CR Bay Trail based tablet in several ways:
1. It uses an analog MIC on IN3 rather then using DMIC1
2. It only has 1 speaker
3. It needs the OVCD current threshold to be set to 1500uA instead of the default 2000uA to reliable differentiate between headphones vs headsets
Add a quirk with these settings for this tablet.
--- sound/soc/intel/boards/bytcr_rt5640.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
sound/soc/intel/boards/bytcr_rt5640.c +15 -0
@@ -428,6 +428,21 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {BYT_RT5640_SSP0_AIF1 | BYT_RT5640_MCLK_EN), }, + { +/* Advantech MICA-071 */ + .matches = { +DMI_EXACT_MATCH (DMI_SYS_VENDOR ,"Advantech" ), + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MICA-071"), + }, +/* OVCD Th = 1500uA to reliable detect head-phones vs -set */ + .driver_data = (void *)(BYT_RT5640_IN3_MAP | +BYT_RT5640_JD_SRC_JD2_IN4N | +BYT_RT5640_OVCD_TH_1500UA | +BYT_RT5640_OVCD_SF_0P75 | +BYT_RT5640_MONO_SPEAKER | +BYT_RT5640_DIFF_MIC | + BYT_RT5640_MCLK_EN), + }, { .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 589/658 x86/bugs: Flush IBP in ib_prctl_set()
In reply to Greg Kroah-HartmanFrom: Rodrigo Branco <[email protected]>
commit a664ec9158eeddd75121d39c9a0758016097fa96 upstream.
We missed the window between the TIF flag update and the next reschedule.
--- arch/x86/kernel/cpu/bugs.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/bugs.c +2 -0
@@ -1787,6 +1787,8 @@ static int ib_prctl_set(struct task_struif (ctrl ==PR_SPEC_FORCE_DISABLE )task_set_spec_ib_force_disable (task);task_update_spec_tif (task); +if (task == current) +indirect_branch_prediction_barrier ();break ;default :return -ERANGE ;
Greg Kroah-Hartman
maintainerPATCH 590/658 nfsd: fix handling of readdir in v4root vs. mount upcall timeout
In reply to Greg Kroah-HartmanFrom: Jeff Layton <[email protected]>
commit cad853374d85fe678d721512cecfabd7636e51f3 upstream.
If v4 READDIR operation hits a mountpoint and gets back an error, then it will include that entry in the reply and set RDATTR_ERROR for it to the error.
That's fine for "normal" exported filesystems, but on the v4root, we need to be more careful to only expose the existence of dentries that lead to exports.
If the mountd upcall times out while checking to see whether a mountpoint on the v4root is exported, then we have no recourse other than to fail the whole operation.
--- fs/nfsd/nfs4xdr.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/nfsd/nfs4xdr.c +11 -0
@@ -3109,6 +3109,17 @@ nfsd4_encode_dirent(void *ccdv, const chcase nfserr_noent:xdr_truncate_encode (xdr, start_offset); goto skip_entry; +case nfserr_jukebox: +/* +* The pseudoroot should only display dentries that lead to +* exports. If we get EJUKEBOX here, then we can't tell whether +* this entry should be included. Just fail the whole READDIR +* with NFS4ERR_DELAY in that case, and hope that the situation +* will resolve itself by the client's next attempt. +*/ +if (cd->rd_fhp->fh_export->ex_flags &NFSEXP_V4ROOT ) + goto fail; + fallthrough;default :/* * If the client requested the RDATTR_ERROR attribute,
Greg Kroah-Hartman
maintainerPATCH 591/658 riscv: uaccess: fix type of 0 variable on error in get_user()
In reply to Greg Kroah-HartmanFrom: Ben Dooks <[email protected]>
commit b9b916aee6715cd7f3318af6dc360c4729417b94 upstream.
If the get_user(x, ptr) has x as a pointer, then the setting of (x) = 0 is going to produce the following sparse warning, so fix this by forcing the type of 'x' when access_ok() fails.
fs/aio.c:2073:21: warning: Using plain integer as NULL pointer
--- arch/riscv/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/uaccess.h +1 -1
@@ -235,7 +235,7 @@ do { \might_fault (); \access_ok (__p,sizeof (*__p)) ? \__get_user ((x), __p) : \ - ((x) =0 , -EFAULT ); \ + ((x) = (__force __typeof__(x))0, -EFAULT); \ })#define __put_user_asm (insn, x, ptr, err) \
Greg Kroah-Hartman
maintainerPATCH 592/658 ext4: dont allow journal inode to have encrypt flag
In reply to Greg Kroah-HartmanFrom: Eric Biggers <[email protected]>
commit 105c78e12468413e426625831faa7db4284e1fec upstream.
Mounting a filesystem whose journal inode has the encrypt flag causes a NULL dereference in fscrypt_limit_io_blocks() when the 'inlinecrypt' mount option is used.
The problem is that when jbd2_journal_init_inode() calls bmap(), it eventually finds its way into ext4_iomap_begin(), which calls fscrypt_limit_io_blocks(). fscrypt_limit_io_blocks() requires that if the inode is encrypted, then its encryption key must already be set up. That's not the case here, since the journal inode is never "opened" like a normal file would be. Hence the crash.
A reproducer is:
mkfs.ext4 -F /dev/vdb
debugfs -w /dev/vdb -R "set_inode_field <8> flags 0x80808" mount /dev/vdb /mnt -o inlinecrypt
To fix this, make ext4 consider journal inodes with the encrypt flag to be invalid. (Note, maybe other flags should be rejected on the journal inode too. For now, this is just the minimal fix for the above issue.)
I've marked this as fixing the commit that introduced the call to fscrypt_limit_io_blocks(), since that's what made an actual crash start being possible. But this fix could be applied to any version of ext4 that supports the encrypt feature.
--- fs/ext4/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/super.c +1 -1
@@ -4836,7 +4836,7 @@ static struct inode *ext4_get_journal_injbd_debug (2 ,"Journal inode found at %p: %lld bytes\n" , journal_inode, journal_inode->i_size); -if (!S_ISREG (journal_inode->i_mode)) { +if (!S_ISREG (journal_inode->i_mode) ||IS_ENCRYPTED (journal_inode)) {ext4_msg (sb,KERN_ERR ,"invalid journal inode" );iput (journal_inode);return NULL ;
Greg Kroah-Hartman
maintainerPATCH 593/658 hfs/hfsplus: use WARN_ON for sanity check
In reply to Greg Kroah-HartmanFrom: Arnd Bergmann <[email protected]>
commit 55d1cbbbb29e6656c662ee8f73ba1fc4777532eb upstream.
gcc warns about a couple of instances in which a sanity check exists but the author wasn't sure how to react to it failing, which makes it look like a possible bug:
fs/hfsplus/inode.c: In function 'hfsplus_cat_read_inode':
fs/hfsplus/inode.c:503:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
503 | /* panic? */;
| ^
fs/hfsplus/inode.c:524:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
524 | /* panic? */;
| ^
fs/hfsplus/inode.c: In function 'hfsplus_cat_write_inode':
fs/hfsplus/inode.c:582:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
582 | /* panic? */;
| ^
fs/hfsplus/inode.c:608:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
608 | /* panic? */;
| ^
fs/hfs/inode.c: In function 'hfs_write_inode':
fs/hfs/inode.c:464:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
464 | /* panic? */;
| ^
fs/hfs/inode.c:485:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
485 | /* panic? */;
| ^panic() is probably not the correct choice here, but a WARN_ON seems appropriate and avoids the compile-time warning.
--- fs/hfs/inode.c | 6 ++---- fs/hfsplus/inode.c | 12 ++++-------- 2 files changed, 6 insertions(+), 12 deletions(-)
fs/hfs/inode.c +2 -4
@@ -461,8 +461,7 @@ int hfs_write_inode(struct inode *inode, goto out;if (S_ISDIR (main_inode->i_mode)) { -if (fd.entrylength <sizeof (struct hfs_cat_dir )) -/* panic? */ ; +WARN_ON (fd.entrylength <sizeof (struct hfs_cat_dir ));hfs_bnode_read (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_dir )); if (rec.type != HFS_CDR_DIR ||
@@ -482,8 +481,7 @@ int hfs_write_inode(struct inode *inode,hfs_bnode_write (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_file )); }else { -if (fd.entrylength <sizeof (struct hfs_cat_file )) -/* panic? */ ; +WARN_ON (fd.entrylength <sizeof (struct hfs_cat_file ));hfs_bnode_read (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_file )); if (rec.type != HFS_CDR_FIL ||
fs/hfsplus/inode.c +4 -8
@@ -497,8 +497,7 @@ int hfsplus_cat_read_inode(struct inodeif (type ==HFSPLUS_FOLDER ) {struct hfsplus_cat_folder *folder = &entry.folder; -if (fd->entrylength <sizeof (struct hfsplus_cat_folder )) -/* panic? */ ; +WARN_ON (fd->entrylength <sizeof (struct hfsplus_cat_folder ));hfs_bnode_read (fd->bnode, &entry, fd->entryoffset,sizeof (struct hfsplus_cat_folder ));hfsplus_get_perms (inode, &folder->permissions,1 );
@@ -518,8 +517,7 @@ int hfsplus_cat_read_inode(struct inode }else if (type ==HFSPLUS_FILE ) {struct hfsplus_cat_file *file = &entry.file; -if (fd->entrylength <sizeof (struct hfsplus_cat_file )) -/* panic? */ ; +WARN_ON (fd->entrylength <sizeof (struct hfsplus_cat_file ));hfs_bnode_read (fd->bnode, &entry, fd->entryoffset,sizeof (struct hfsplus_cat_file ));
@@ -576,8 +574,7 @@ int hfsplus_cat_write_inode(struct inodeif (S_ISDIR (main_inode->i_mode)) {struct hfsplus_cat_folder *folder = &entry.folder; -if (fd.entrylength <sizeof (struct hfsplus_cat_folder )) -/* panic? */ ; +WARN_ON (fd.entrylength <sizeof (struct hfsplus_cat_folder ));hfs_bnode_read (fd.bnode, &entry, fd.entryoffset,sizeof (struct hfsplus_cat_folder ));/* simple node checks? */
@@ -602,8 +599,7 @@ int hfsplus_cat_write_inode(struct inode }else {struct hfsplus_cat_file *file = &entry.file; -if (fd.entrylength <sizeof (struct hfsplus_cat_file )) -/* panic? */ ; +WARN_ON (fd.entrylength <sizeof (struct hfsplus_cat_file ));hfs_bnode_read (fd.bnode, &entry, fd.entryoffset,sizeof (struct hfsplus_cat_file ));hfsplus_inode_write_fork (inode, &file->data_fork);
Greg Kroah-Hartman
maintainerPATCH 594/658 hfs/hfsplus: avoid WARN_ON() for sanity check, use proper error handling
In reply to Greg Kroah-HartmanFrom: Linus Torvalds <[email protected]>
commit cb7a95af78d29442b8294683eca4897544b8ef46 upstream.
Commit 55d1cbbbb29e ("hfs/hfsplus: use WARN_ON for sanity check") fixed a build warning by turning a comment into a WARN_ON(), but it turns out that syzbot then complains because it can trigger said warning with a corrupted hfs image.
The warning actually does warn about a bad situation, but we are much better off just handling it as the error it is. So rather than warn about us doing bad things, stop doing the bad things and return -EIO.
While at it, also fix a memory leak that was introduced by an earlier fix for a similar syzbot warning situation, and add a check for one case that historically wasn't handled at all (ie neither comment nor subsequent WARN_ON).
--- fs/hfs/inode.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
fs/hfs/inode.c +10 -5
@@ -453,15 +453,16 @@ int hfs_write_inode(struct inode *inode,/* panic? */ return -EIO ; + res = -EIO ;if (HFS_I (main_inode)->cat_key.CName.len >HFS_NAMELEN ) -return -EIO ; + goto out; fd.search_key->cat =HFS_I (main_inode)->cat_key;if (hfs_brec_find (&fd)) -/* panic? */ goto out;if (S_ISDIR (main_inode->i_mode)) { -WARN_ON (fd.entrylength <sizeof (struct hfs_cat_dir )); +if (fd.entrylength <sizeof (struct hfs_cat_dir )) + goto out;hfs_bnode_read (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_dir )); if (rec.type != HFS_CDR_DIR ||
@@ -474,6 +475,8 @@ int hfs_write_inode(struct inode *inode,hfs_bnode_write (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_dir )); }else if (HFS_IS_RSRC (inode)) { +if (fd.entrylength <sizeof (struct hfs_cat_file )) + goto out;hfs_bnode_read (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_file )); hfs_inode_write_fork(inode, rec.file.RExtRec,
@@ -481,7 +484,8 @@ int hfs_write_inode(struct inode *inode,hfs_bnode_write (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_file )); }else { -WARN_ON (fd.entrylength <sizeof (struct hfs_cat_file )); +if (fd.entrylength <sizeof (struct hfs_cat_file )) + goto out;hfs_bnode_read (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_file )); if (rec.type != HFS_CDR_FIL ||
@@ -498,9 +502,10 @@ int hfs_write_inode(struct inode *inode,hfs_bnode_write (fd.bnode, &rec, fd.entryoffset,sizeof (struct hfs_cat_file )); } + res =0 ; out:hfs_find_exit (&fd); -return 0 ; +return res; } static struct dentry *hfs_file_lookup(struct inode *dir, struct dentry *dentry,
Greg Kroah-Hartman
maintainerPATCH 595/658 mbcache: Avoid nesting of cache->c_list_lock under bit locks
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
commit 5fc4cbd9fde5d4630494fd6ffc884148fb618087 upstream.
Commit 307af6c87937 ("mbcache: automatically delete entries from cache on freeing") started nesting cache->c_list_lock under the bit locks protecting hash buckets of the mbcache hash table in mb_cache_entry_create(). This causes problems for real-time kernels because there spinlocks are sleeping locks while bitlocks stay atomic. Luckily the nesting is easy to avoid by holding entry reference until the entry is added to the LRU list. This makes sure we cannot race with entry deletion.
--- fs/mbcache.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
fs/mbcache.c +10 -7
@@ -90,8 +90,14 @@ int mb_cache_entry_create(struct mb_cachreturn -ENOMEM ;INIT_LIST_HEAD (&entry->e_list); -/* Initial hash reference */ -atomic_set (&entry->e_refcnt,1 ); +/* +* We create entry with two references. One reference is kept by the +* hash table, the other reference is used to protect us from +* mb_cache_entry_delete_or_get() until the entry is fully setup. This +* avoids nesting of cache->c_list_lock into hash table bit locks which +* is problematic for RT. +*/ +atomic_set (&entry->e_refcnt,2 ); entry->e_key = key; entry->e_value = value; entry->e_flags =0 ;
@@ -107,15 +113,12 @@ int mb_cache_entry_create(struct mb_cach } }hlist_bl_add_head (&entry->e_hash_list, head); -/* -* Add entry to LRU list before it can be found by -* mb_cache_entry_delete() to avoid races -*/ +hlist_bl_unlock (head);spin_lock (&cache->c_list_lock);list_add_tail (&entry->e_list, &cache->c_list); cache->c_entry_count++;spin_unlock (&cache->c_list_lock); -hlist_bl_unlock (head); +mb_cache_entry_put (cache, entry);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 596/658 parisc: Align parisc MADV_XXX constants with all other architectures
In reply to Greg Kroah-HartmanFrom: Helge Deller <[email protected]>
commit 71bdea6f798b425bc0003780b13e3fdecb16a010 upstream.
Adjust some MADV_XXX constants to be in sync what their values are on all other platforms. There is currently no reason to have an own numbering on parisc, but it requires workarounds in many userspace sources (e.g. glibc, qemu, ...) - which are often forgotten and thus introduce bugs and different behaviour on parisc.
A wrapper avoids an ABI breakage for existing userspace applications by translating any old values to the new ones, so this change allows us to move over all programs to the new ABI over time.
---
--- arch/parisc/include/uapi/asm/mman.h | 23 +++++++++++------------ arch/parisc/kernel/sys_parisc.c | 27 +++++++++++++++++++++++++++ arch/parisc/kernel/syscalls/syscall.tbl | 2 +- tools/arch/parisc/include/uapi/asm/mman.h | 12 ++++++------ tools/perf/bench/bench.h | 12 ------------ 5 files changed, 45 insertions(+), 31 deletions(-)
arch/parisc/include/uapi/asm/mman.h +11 -12
@@ -48,28 +48,27 @@#define MADV_DONTFORK 10/* don't inherit across fork */ #define MADV_DOFORK 11/* do inherit across fork */ -#define MADV_COLD 20/* deactivate these pages */ -#define MADV_PAGEOUT 21/* reclaim these pages */ - -#define MADV_MERGEABLE 65/* KSM may merge identical pages */ -#define MADV_UNMERGEABLE 66/* KSM may not merge identical pages */ +#define MADV_MERGEABLE 12/* KSM may merge identical pages */ +#define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ -#define MADV_HUGEPAGE 67/* Worth backing with hugepages */ -#define MADV_NOHUGEPAGE 68/* Not worth backing with hugepages */ +#define MADV_HUGEPAGE 14/* Worth backing with hugepages */ +#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ -#define MADV_DONTDUMP 69/* Explicity exclude from the core dump, +#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 70/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ -#define MADV_WIPEONFORK 71/* Zero memory on fork, child only */ -#define MADV_KEEPONFORK 72/* Undo MADV_WIPEONFORK */ +#define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ +#define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ + +#define MADV_COLD 20/* deactivate these pages */ +#define MADV_PAGEOUT 21/* reclaim these pages */ #define MADV_HWPOISON 100/* poison a page for testing */ #define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ /* compatibility flags */ #define MAP_FILE 0 -#define MAP_VARIABLE 0#define PKEY_DISABLE_ACCESS 0x1#define PKEY_DISABLE_WRITE 0x2
arch/parisc/kernel/sys_parisc.c +27 -0
@@ -373,3 +373,30 @@ long parisc_personality(unsigned long pereturn err; } + +/* +* madvise() wrapper +* +* Up to kernel v6.1 parisc has different values than all other +* platforms for the MADV_xxx flags listed below. +* To keep binary compatibility with existing userspace programs +* translate the former values to the new values. +* +* XXX: Remove this wrapper in year 2025 (or later) +*/ + +asmlinkage notrace long parisc_madvise(unsigned long start, size_t len_in, int behavior) +{ +switch (behavior) { +case 65 : behavior =MADV_MERGEABLE ;break ; +case 66 : behavior =MADV_UNMERGEABLE ;break ; +case 67 : behavior =MADV_HUGEPAGE ;break ; +case 68 : behavior =MADV_NOHUGEPAGE ;break ; +case 69 : behavior =MADV_DONTDUMP ;break ; +case 70 : behavior =MADV_DODUMP ;break ; +case 71 : behavior =MADV_WIPEONFORK ;break ; +case 72 : behavior =MADV_KEEPONFORK ;break ; + } + +return sys_madvise (start, len_in, behavior); +}
arch/parisc/kernel/syscalls/syscall.tbl +1 -1
@@ -131,7 +131,7 @@ 116 common sysinfo sys_sysinfo compat_sys_sysinfo 117 common shutdown sys_shutdown 118 common fsync sys_fsync -119 common madvise sys_madvise +119 common madvise parisc_madvise 120 common clone sys_clone_wrapper 121 common setdomainname sys_setdomainname 122 common sendfile sys_sendfile compat_sys_sendfile
tools/arch/parisc/include/uapi/asm/mman.h +6 -6
@@ -1,20 +1,20 @@/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ #ifndef TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H #define TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H -#define MADV_DODUMP 70 +#define MADV_DODUMP 17#define MADV_DOFORK 11 -#define MADV_DONTDUMP 69 +#define MADV_DONTDUMP 16#define MADV_DONTFORK 10#define MADV_DONTNEED 4#define MADV_FREE 8 -#define MADV_HUGEPAGE 67 -#define MADV_MERGEABLE 65 -#define MADV_NOHUGEPAGE 68 +#define MADV_HUGEPAGE 14 +#define MADV_MERGEABLE 12 +#define MADV_NOHUGEPAGE 15#define MADV_NORMAL 0#define MADV_RANDOM 1#define MADV_REMOVE 9#define MADV_SEQUENTIAL 2 -#define MADV_UNMERGEABLE 66 +#define MADV_UNMERGEABLE 13#define MADV_WILLNEED 3#define MAP_ANONYMOUS 0x10#define MAP_DENYWRITE 0x0800
tools/perf/bench/bench.h +0 -12
@@ -10,25 +10,13 @@ extern struct timeval bench__start, benc* The madvise transparent hugepage constants were added in glibc * 2.13. For compatibility with older versions of glibc, define these * tokens if they are not already defined. -* -* PA-RISC uses different madvise values from other architectures and -* needs to be special-cased. */ -#ifdef __hppa__ -# ifndef MADV_HUGEPAGE -# define MADV_HUGEPAGE 67 -# endif -# ifndef MADV_NOHUGEPAGE -# define MADV_NOHUGEPAGE 68 -# endif -#else # ifndef MADV_HUGEPAGE # define MADV_HUGEPAGE 14# endif # ifndef MADV_NOHUGEPAGE # define MADV_NOHUGEPAGE 15# endif -#endif int bench_numa (int argc,const char **argv);int bench_sched_messaging (int argc,const char **argv);
Greg Kroah-Hartman
maintainerPATCH 597/658 selftests: Fix kselftest O=objdir build from cluttering top level objdir
In reply to Greg Kroah-HartmanFrom: Shuah Khan <[email protected]>
commit 29e911ef7b706215caf02a82b0d3076611d6abe8 upstream.
make kselftest-all O=objdir builds create generated objects in objdir. This clutters the top level directory with kselftest objects. Fix it to create sub-directory under objdir for kselftest objects.
--- tools/testing/selftests/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/Makefile +2 -2
@@ -78,7 +78,7 @@ override LDFLAGS = override MAKEFLAGS = endif -# Append kselftest to KBUILD_OUTPUT to avoid cluttering +# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering # KBUILD_OUTPUT with selftest objects and headers installed # by selftests Makefile or lib.mk. ifdef building_out_of_srctree
@@ -86,7 +86,7 @@ override LDFLAGS = endif ifneq ($(O),) - BUILD := $(O) + BUILD := $(O)/kselftest else ifneq ($(KBUILD_OUTPUT),) BUILD := $(KBUILD_OUTPUT)/kselftest
Greg Kroah-Hartman
maintainerPATCH 598/658 selftests: set the BUILD variable to absolute path
In reply to Greg Kroah-HartmanFrom: Muhammad Usama Anjum <[email protected]>
commit 5ad51ab618de5d05f4e692ebabeb6fe6289aaa57 upstream.
The build of kselftests fails if relative path is specified through KBUILD_OUTPUT or O=<path> method. BUILD variable is used to determine the path of the output objects. When make is run from other directories with relative paths, the exact path of the build objects is ambiguous and build fails.
make[1]: Entering directory '/home/usama/repos/kernel/linux_mainline2/tools/testing/selftests/alsa'
gcc mixer-test.c -L/usr/lib/x86_64-linux-gnu -lasound -o build/kselftest/alsa/mixer-test
/usr/bin/ld: cannot open output file build/kselftest/alsa/mixer-test
Set the BUILD variable to the absolute path of the output directory. Make the logic readable and easy to follow. Use spaces instead of tabs for indentation as if with tab indentation is considered recipe in make.
--- tools/testing/selftests/Makefile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
tools/testing/selftests/Makefile +17 -9
@@ -85,19 +85,27 @@ ifdef building_out_of_srctree override LDFLAGS = endif -ifneq ($(O),) - BUILD := $(O)/kselftest +top_srcdir ?= ../../.. + +ifeq ("$(origin O)", "command line") + KBUILD_OUTPUT := $(O) +endif + +ifneq ($(KBUILD_OUTPUT),) + # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot + # expand a shell special character '~'. We use a somewhat tedious way here. + abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) + $(if $(abs_objtree),, \ + $(error failed to create output directory "$(KBUILD_OUTPUT)")) + # $(realpath ...) resolves symlinks + abs_objtree := $(realpath $(abs_objtree)) + BUILD := $(abs_objtree)/kselftest else - ifneq ($(KBUILD_OUTPUT),) - BUILD := $(KBUILD_OUTPUT)/kselftest - else - BUILD := $(shell pwd) - DEFAULT_INSTALL_HDR_PATH := 1 - endif + BUILD := $(CURDIR) + DEFAULT_INSTALL_HDR_PATH := 1 endif # Prepare for headers install -top_srcdir ?= ../../.. include $(top_srcdir)/scripts/subarch.include ARCH ?= $(SUBARCH) export KSFT_KHDR_INSTALL_DONE := 1
Greg Kroah-Hartman
maintainerPATCH 599/658 driver core: Fix bus_type.match() error handling in __driver_attach()
In reply to Greg Kroah-HartmanFrom: Isaac J. Manjarres <[email protected]>
commit 27c0d217340e47ec995557f61423ef415afba987 upstream.
When a driver registers with a bus, it will attempt to match with every device on the bus through the __driver_attach() function. Currently, if the bus_type.match() function encounters an error that is not -EPROBE_DEFER, __driver_attach() will return a negative error code, which causes the driver registration logic to stop trying to match with the remaining devices on the bus.
This behavior is not correct; a failure while matching a driver to a device does not mean that the driver won't be able to match and bind with other devices on the bus. Update the logic in __driver_attach() to reflect this.
--- drivers/base/dd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/base/dd.c +6 -2
@@ -1068,8 +1068,12 @@ static int __driver_attach(struct device*/ return 0 ; }else if (ret <0 ) { -dev_dbg (dev,"Bus failed to match device: %d" , ret); -return ret; +dev_dbg (dev,"Bus failed to match device: %d\n" , ret); +/* +* Driver could not match with device, but may match with +* another device on the bus. +*/ +return 0 ; }/* ret > 0 means positive match */ if (driver_allows_async_probing (drv)) {
Greg Kroah-Hartman
maintainerPATCH 600/658 net: sched: disallow noqueue for qdisc classes
In reply to Greg Kroah-HartmanFrom: Frederick Lawler <[email protected]>
commit 96398560f26aa07e8f2969d73c8197e6a6d10407 upstream.
While experimenting with applying noqueue to a classful queue discipline, we discovered a NULL pointer dereference in the __dev_queue_xmit() path that generates a kernel OOPS:
# dev=enp0s5
# tc qdisc replace dev $dev root handle 1: htb default 1 # tc class add dev $dev parent 1: classid 1:1 htb rate 10mbit # tc qdisc add dev $dev parent 1:1 handle 10: noqueue # ping -I $dev -w 1 -c 1 1.1.1.1
[ 2.172856] BUG: kernel NULL pointer dereference, address: 0000000000000000 [ 2.173217] #PF: supervisor instruction fetch in kernel mode ... [ 2.178451] Call Trace: [ 2.178577] <TASK> [ 2.178686] htb_enqueue+0x1c8/0x370 [ 2.178880] dev_qdisc_enqueue+0x15/0x90 [ 2.179093] __dev_queue_xmit+0x798/0xd00 [ 2.179305] ? _raw_write_lock_bh+0xe/0x30 [ 2.179522] ? __local_bh_enable_ip+0x32/0x70 [ 2.179759] ? ___neigh_create+0x610/0x840 [ 2.179968] ? eth_header+0x21/0xc0 [ 2.180144] ip_finish_output2+0x15e/0x4f0 [ 2.180348] ? dst_output+0x30/0x30 [ 2.180525] ip_push_pending_frames+0x9d/0xb0 [ 2.180739] raw_sendmsg+0x601/0xcb0 [ 2.180916] ? _raw_spin_trylock+0xe/0x50 [ 2.181112] ? _raw_spin_unlock_irqrestore+0x16/0x30 [ 2.181354] ? get_page_from_freelist+0xcd6/0xdf0 [ 2.181594] ? sock_sendmsg+0x56/0x60 [ 2.181781] sock_sendmsg+0x56/0x60 [ 2.181958] __sys_sendto+0xf7/0x160 [ 2.182139] ? handle_mm_fault+0x6e/0x1d0 [ 2.182366] ? do_user_addr_fault+0x1e1/0x660 [ 2.182627] __x64_sys_sendto+0x1b/0x30 [ 2.182881] do_syscall_64+0x38/0x90 [ 2.183085] entry_SYSCALL_64_after_hwframe+0x63/0xcd ... [ 2.187402] </TASK>
Previously in commit d66d6c3152e8 ("net: sched: register noqueue qdisc"), NULL was set for the noqueue discipline on noqueue init so that __dev_queue_xmit() falls through for the noqueue case. This also sets a bypass of the enqueue NULL check in the register_qdisc() function for the struct noqueue_disc_ops.
Classful queue disciplines make it past the NULL check in __dev_queue_xmit() because the discipline is set to htb (in this case), and then in the call to __dev_xmit_skb(), it calls into htb_enqueue() which grabs a leaf node for a class and then calls qdisc_enqueue() by passing in a queue discipline which assumes ->enqueue() is not set to NULL.
Fix this by not allowing classes to be assigned to the noqueue discipline. Linux TC Notes states that classes cannot be set to the noqueue discipline. [1] Let's enforce that here.
Links:
1. https://linux-tc-notes.sourceforge.net/tc/doc/sch_noqueue.txt
--- net/sched/sch_api.c | 5 +++++ 1 file changed, 5 insertions(+)
net/sched/sch_api.c +5 -0
@@ -1104,6 +1104,11 @@ skip:return -ENOENT ; } +if (new && new->ops == &noqueue_qdisc_ops) { +NL_SET_ERR_MSG (extack,"Cannot assign noqueue to a class" ); +return -EINVAL ; + } + err = cops->graft (parent, cl, new, &old, extack);if (err)return err;
Greg Kroah-Hartman
maintainerPATCH 601/658 KVM: arm64: Fix S1PTW handling on RO memslots
In reply to Greg Kroah-HartmanFrom: Marc Zyngier <[email protected]>
commit 406504c7b0405d74d74c15a667cd4c4620c3e7a9 upstream.
A recent development on the EFI front has resulted in guests having their page tables baked in the firmware binary, and mapped into the IPA space as part of a read-only memslot. Not only is this legitimate, but it also results in added security, so thumbs up.
It is possible to take an S1PTW translation fault if the S1 PTs are unmapped at stage-2. However, KVM unconditionally treats S1PTW as a write to correctly handle hardware AF/DB updates to the S1 PTs. Furthermore, KVM injects an exception into the guest for S1PTW writes. In the aforementioned case this results in the guest taking an abort it won't recover from, as the S1 PTs mapping the vectors suffer from the same problem.
So clearly our handling is... wrong.
Instead, switch to a two-pronged approach:
- On S1PTW translation fault, handle the fault as a read
- On S1PTW permission fault, handle the fault as a write
This is of no consequence to SW that *writes* to its PTs (the write will trigger a non-S1PTW fault), and SW that uses RO PTs will not use HW-assisted AF/DB anyway, as that'd be wrong.
Only in the case described in c4ad98e4b72c ("KVM: arm64: Assume write fault on S1PTW permission fault on instruction fetch") do we end-up with two back-to-back faults (page being evicted and faulted back). I don't think this is a case worth optimising for.
--- arch/arm64/include/asm/kvm_emulate.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +20 -2
@@ -378,8 +378,26 @@ static inline int kvm_vcpu_sys_get_rt(ststatic inline bool kvm_is_write_fault (struct kvm_vcpu *vcpu) { -if (kvm_vcpu_abt_iss1tw (vcpu)) -return true; +if (kvm_vcpu_abt_iss1tw (vcpu)) { +/* +* Only a permission fault on a S1PTW should be +* considered as a write. Otherwise, page tables baked +* in a read-only memslot will result in an exception +* being delivered in the guest. +* +* The drawback is that we end-up faulting twice if the +* guest is using any of HW AF/DB: a translation fault +* to map the page containing the PT (read only at +* first), then a permission fault to allow the flags +* to be set. +*/ +switch (kvm_vcpu_trap_get_fault_type (vcpu)) { +case ESR_ELx_FSC_PERM: +return true; +default : +return false; + } + }if (kvm_vcpu_trap_is_iabt (vcpu))return false;
Greg Kroah-Hartman
maintainerPATCH 602/658 efi: tpm: Avoid READ_ONCE() for accessing the event log
In reply to Greg Kroah-HartmanFrom: Ard Biesheuvel <[email protected]>
commit d3f450533bbcb6dd4d7d59cadc9b61b7321e4ac1 upstream.
Nathan reports that recent kernels built with LTO will crash when doing EFI boot using Fedora's GRUB and SHIM. The culprit turns out to be a misaligned load from the TPM event log, which is annotated with READ_ONCE(), and under LTO, this gets translated into a LDAR instruction which does not tolerate misaligned accesses.
Interestingly, this does not happen when booting the same kernel straight from the UEFI shell, and so the fact that the event log may appear misaligned in memory may be caused by a bug in GRUB or SHIM.
However, using READ_ONCE() to access firmware tables is slightly unusual in any case, and here, we only need to ensure that 'event' is not dereferenced again after it gets unmapped, but this is already taken care of by the implicit barrier() semantics of the early_memunmap() call.
--- include/linux/tpm_eventlog.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/tpm_eventlog.h +2 -2
@@ -198,8 +198,8 @@ static __always_inline int __calc_tpm2_e* The loop below will unmap these fields if the log is larger than * one page, so save them here for reference: */ - count =READ_ONCE (event->count); - event_type =READ_ONCE (event->event_type); + count = event->count; + event_type = event->event_type;/* Verify that it's the log header */ if (event_header->pcr_idx != 0 ||
Greg Kroah-Hartman
maintainerPATCH 603/658 docs: Fix the docs build with Sphinx 6.0
In reply to Greg Kroah-HartmanFrom: Jonathan Corbet <[email protected]>
commit 0283189e8f3d0917e2ac399688df85211f48447b upstream.
Sphinx 6.0 removed the execfile_() function, which we use as part of the configuration process. They *did* warn us... Just open-code the functionality as is done in Sphinx itself.
Tested (using SPHINX_CONF, since this code is only executed with an alternative config file) on various Sphinx versions from 2.5 through 6.0.
--- Documentation/sphinx/load_config.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/sphinx/load_config.py +4 -2
@@ -3,7 +3,7 @@ import os import sys -from sphinx.util.pycompat import execfile_ +from sphinx.util.osutil import fs_encoding # ------------------------------------------------------------------------------ def loadConfig(namespace):
@@ -48,7 +48,9 @@ def loadConfig(namespace): sys.stdout.write("load additional sphinx-config: %s\n" % config_file) config = namespace.copy() config['__file__'] = config_file - execfile_(config_file, config) + with open(config_file, 'rb') as f: + code = compile(f.read(), fs_encoding, 'exec') + exec(code, config) del config['__file__'] namespace.update(config) else:
Greg Kroah-Hartman
maintainerPATCH 604/658 perf auxtrace: Fix address filter duplicate symbol selection
In reply to Greg Kroah-HartmanFrom: Adrian Hunter <[email protected]>
commit cf129830ee820f7fc90b98df193cd49d49344d09 upstream.
When a match has been made to the nth duplicate symbol, return success not error.
Example:
Before:
$ cat file.c
cat: file.c: No such file or directory
$ cat file1.c
#include <stdio.h> static void func(void)
{
printf("First func\n");
}
void other(void);
int main()
{
func();
other();
return 0;
}
$ cat file2.c
#include <stdio.h>
static void func(void)
{
printf("Second func\n");
}
void other(void)
{
func();
}
$ gcc -Wall -Wextra -o test file1.c file2.c
$ perf record -e intel_pt//u --filter 'filter func @ ./test' -- ./test
Multiple symbols with name 'func'
#1 0x1149 l func
which is near main
#2 0x1179 l func
which is near other
Disambiguate symbol name by inserting #n after the name e.g. func #2
Or select a global symbol by inserting #0 or #g or #G
Failed to parse address filter: 'filter func @ ./test'
Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>]
Where multiple filters are separated by space or comma.
$ perf record -e intel_pt//u --filter 'filter func #2 @ ./test' -- ./test
Failed to parse address filter: 'filter func #2 @ ./test'
Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>]
Where multiple filters are separated by space or comma.After:
$ perf record -e intel_pt//u --filter 'filter func #2 @ ./test' -- ./test
First func
Second func
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.016 MB perf.data ]
$ perf script --itrace=b -Ftime,flags,ip,sym,addr --ns
1231062.526977619: tr strt 0 [unknown] => 558495708179 func
1231062.526977619: tr end call 558495708188 func => 558495708050 _init
1231062.526979286: tr strt 0 [unknown] => 55849570818d func
1231062.526979286: tr end return 55849570818f func => 55849570819d other--- tools/perf/util/auxtrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/auxtrace.c +1 -1
@@ -1995,7 +1995,7 @@ static int find_dso_sym(struct dso *dso, *size = sym->start - *start;if (idx >0 ) {if (*size) -return 1 ; +return 0 ; }else if (dso_sym_match (sym, sym_name, &cnt, idx)) {print_duplicate_syms (dso, sym_name);return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 605/658 s390/kexec: fix ipl report address for kdump
In reply to Greg Kroah-HartmanFrom: Alexander Egorenkov <[email protected]>
commit c2337a40e04dde1692b5b0a46ecc59f89aaba8a1 upstream.
This commit addresses the following erroneous situation with file-based kdump executed on a system with a valid IPL report.
On s390, a kdump kernel, its initrd and IPL report if present are loaded into a special and reserved on boot memory region - crashkernel. When a system crashes and kdump was activated before, the purgatory code is entered first which swaps the crashkernel and [0 - crashkernel size] memory regions. Only after that the kdump kernel is entered. For this reason, the pointer to an IPL report in lowcore must point to the IPL report after the swap and not to the address of the IPL report that was located in crashkernel memory region before the swap. Failing to do so, makes the kdump's decompressor try to read memory from the crashkernel memory region which already contains the production's kernel memory.
The situation described above caused spontaneous kdump failures/hangs on systems where the Secure IPL is activated because on such systems an IPL report is always present. In that case kdump's decompressor tried to parse an IPL report which frequently lead to illegal memory accesses because an IPL report contains addresses to various data.
--- arch/s390/kernel/machine_kexec_file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/s390/kernel/machine_kexec_file.c +3 -2
@@ -185,8 +185,6 @@ static int kexec_file_add_ipl_report(str data->memsz =ALIGN (data->memsz,PAGE_SIZE ); buf.mem = data->memsz; -if (image->type ==KEXEC_TYPE_CRASH ) - buf.mem += crashk_res.start; ptr = (void *)ipl_cert_list_addr; end = ptr + ipl_cert_list_size;
@@ -223,6 +221,9 @@ static int kexec_file_add_ipl_report(str data->kernel_buf + offsetof(struct lowcore , ipl_parmblock_ptr); *lc_ipl_parmblock_ptr = (__u32 )buf.mem; +if (image->type ==KEXEC_TYPE_CRASH ) + buf.mem += crashk_res.start; + ret =kexec_add_buffer (&buf); out:return ret;