Hi, I'm not a kernel developer, but I checked how FreeBSD handles socket stats (soo_stat() in sys/kern/sys_socket.c). On FreeBSD, fstat() on a socket returns st_dev = NODEV and st_ino = 0. Since st_ino is always 0 for sockets, it isn't unique or usable for verification either. So your proposed patch to skip the entire check when st_dev == (dev_t)-1 is indeed the right approach. KR, Jordan
On 5 Aug 2026, at 23:56, Timo Sirainen <timo@sirainen.com> wrote:
Hi,
I'm mainly wondering if the device is NODEV, is the inode still usable or is that also some 0 or -1? This is likely a simpler patch, but it also removes the inode check also, which isn't good if it would be usable:
diff --git a/src/imap/imap-client-hibernate.c b/src/imap/imap-client-hibernate.c index cb640c3695..191b0cfef9 100644 --- a/src/imap/imap-client-hibernate.c +++ b/src/imap/imap-client-hibernate.c @@ -62,7 +62,10 @@ static void imap_hibernate_write_cmd(struct client *client, string_t *cmd, str_append_tabescaped(cmd, user->set->unexpanded_mail_log_prefix); str_printfa(cmd, "\tidle_notify_interval=%u", client->set->imap_idle_notify_interval); - if (fstat(client->fd_in, &peer_st) == 0) { + /* e.g. FreeBSD returns NODEV as sockets' st_dev, which can't be + used for verifying that the fd is the expected one. */ + if (fstat(client->fd_in, &peer_st) == 0 && + peer_st.st_dev != (dev_t)-1) { str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev),
Hi, I'm not a kernel developer, but I checked how FreeBSD handles socket stats (soo_stat() in sys/kern/sys_socket.c). On FreeBSD, fstat() on a socket returns st_dev = NODEV and st_ino = 0. Since st_ino is always 0 for sockets, it isn't unique or usable for verification either. So your proposed patch to skip the entire check when st_dev == (dev_t)-1 is indeed the right approach. KR, Jordan On 5 Aug 2026, at 23:56, Timo Sirainen <timo@sirainen.com> wrote: Hi, I'm mainly wondering if the device is NODEV, is the inode still usable or is that also some 0 or -1? This is likely a simpler patch, but it also removes the inode check also, which isn't good if it would be usable: diff --git a/src/imap/imap-client-hibernate.c b/src/imap/imap-client-hibernate.c index cb640c3695..191b0cfef9 100644 --- a/src/imap/imap-client-hibernate.c +++ b/src/imap/imap-client-hibernate.c @@ -62,7 +62,10 @@ static void imap_hibernate_write_cmd(struct client *client, string_t *cmd, str_append_tabescaped(cmd, user->set->unexpanded_mail_log_prefix); str_printfa(cmd, "\tidle_notify_interval=%u", client->set->imap_idle_notify_interval); - if (fstat(client->fd_in, &peer_st) == 0) { + /* e.g. FreeBSD returns NODEV as sockets' st_dev, which can't be + used for verifying that the fd is the expected one. */ + if (fstat(client->fd_in, &peer_st) == 0 && + peer_st.st_dev != (dev_t)-1) { str_printfa(cmd, "\tpeer_dev_major=%lu\tpeer_dev_minor=%lu\tpeer_ino=%llu", (unsigned long)major(peer_st.st_dev), (unsigned long)minor(peer_st.st_dev),